Run cc tests if any are found in the examples folder

This commit is contained in:
Alexandru Ene
2020-06-19 00:09:33 +01:00
parent 65e132db0c
commit 9213717917

View File

@@ -51,7 +51,7 @@ fn main() {
.arg("--example") .arg("--example")
.arg(&example)); .arg(&example));
println!("======== C example `{}` ============", example); println!("======== C/C++ example `{}` ============", example);
let mut cmd = cc::Build::new() let mut cmd = cc::Build::new()
.opt_level(0) .opt_level(0)
.cargo_metadata(false) .cargo_metadata(false)
@@ -63,11 +63,20 @@ fn main() {
.warnings(false) .warnings(false)
.get_compiler() .get_compiler()
.to_command(); .to_command();
if is_dir {
cmd.arg(format!("examples/{}/main.c", example)); for extension in ["c", "cc"].iter() {
let file = if is_dir {
format!("examples/{}/main.{}", example, extension)
} else { } else {
cmd.arg(format!("examples/{}.c", example)); format!("examples/{}.{}", example, extension)
};
if extension == &"cc" && !std::path::Path::new(&file).exists() {
// cc files are optional so we can skip them.
continue;
} }
cmd.arg(file);
let exe = if cfg!(windows) { let exe = if cfg!(windows) {
cmd.arg("target/debug/wasmtime.lib") cmd.arg("target/debug/wasmtime.lib")
.arg("ws2_32.lib") .arg("ws2_32.lib")
@@ -88,6 +97,7 @@ fn main() {
run(&mut Command::new(exe)); run(&mut Command::new(exe));
} }
}
} }
fn run(cmd: &mut Command) { fn run(cmd: &mut Command) {