From 92137179174a56a75ded7085a4d94ae8f85d75d0 Mon Sep 17 00:00:00 2001 From: Alexandru Ene Date: Fri, 19 Jun 2020 00:09:33 +0100 Subject: [PATCH] Run cc tests if any are found in the examples folder --- crates/misc/run-examples/src/main.rs | 58 ++++++++++++++++------------ 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/crates/misc/run-examples/src/main.rs b/crates/misc/run-examples/src/main.rs index f782b929cb..d9a44c74fd 100644 --- a/crates/misc/run-examples/src/main.rs +++ b/crates/misc/run-examples/src/main.rs @@ -51,7 +51,7 @@ fn main() { .arg("--example") .arg(&example)); - println!("======== C example `{}` ============", example); + println!("======== C/C++ example `{}` ============", example); let mut cmd = cc::Build::new() .opt_level(0) .cargo_metadata(false) @@ -63,30 +63,40 @@ fn main() { .warnings(false) .get_compiler() .to_command(); - if is_dir { - cmd.arg(format!("examples/{}/main.c", example)); - } else { - cmd.arg(format!("examples/{}.c", example)); - } - let exe = if cfg!(windows) { - cmd.arg("target/debug/wasmtime.lib") - .arg("ws2_32.lib") - .arg("advapi32.lib") - .arg("userenv.lib") - .arg("ntdll.lib") - .arg("shell32.lib") - .arg("ole32.lib"); - "./main.exe" - } else { - cmd.arg("target/debug/libwasmtime.a").arg("-o").arg("foo"); - "./foo" - }; - if cfg!(target_os = "linux") { - cmd.arg("-lpthread").arg("-ldl").arg("-lm"); - } - run(&mut cmd); - run(&mut Command::new(exe)); + for extension in ["c", "cc"].iter() { + let file = if is_dir { + format!("examples/{}/main.{}", example, extension) + } else { + 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) { + cmd.arg("target/debug/wasmtime.lib") + .arg("ws2_32.lib") + .arg("advapi32.lib") + .arg("userenv.lib") + .arg("ntdll.lib") + .arg("shell32.lib") + .arg("ole32.lib"); + "./main.exe" + } else { + cmd.arg("target/debug/libwasmtime.a").arg("-o").arg("foo"); + "./foo" + }; + if cfg!(target_os = "linux") { + cmd.arg("-lpthread").arg("-ldl").arg("-lm"); + } + run(&mut cmd); + + run(&mut Command::new(exe)); + } } }