diff --git a/wasm3-sys/Cargo.toml b/wasm3-sys/Cargo.toml index 156cea1..632b109 100644 --- a/wasm3-sys/Cargo.toml +++ b/wasm3-sys/Cargo.toml @@ -22,10 +22,11 @@ cty = "0.2" [build-dependencies] cc = "1" +shlex = "0.1.1" [build-dependencies.bindgen] version = "0.54" optional = true [package.metadata.docs.rs] -all-features = true \ No newline at end of file +all-features = true diff --git a/wasm3-sys/build.rs b/wasm3-sys/build.rs index 16df4b4..28c73a8 100644 --- a/wasm3-sys/build.rs +++ b/wasm3-sys/build.rs @@ -125,8 +125,9 @@ fn gen_bindings() { fn main() { gen_bindings(); - // build + let mut cfg = cc::Build::new(); + cfg.files( fs::read_dir(WASM3_SOURCE) .unwrap_or_else(|_| panic!("failed to read {} directory", WASM3_SOURCE)) @@ -134,15 +135,29 @@ fn main() { .map(|entry| entry.path()) .filter(|p| p.extension().and_then(OsStr::to_str) == Some("c")), ); - let cfg = cfg - .warnings(false) - .cpp(false) + + cfg.cpp(false) .define("d_m3LogOutput", Some("0")) + .warnings(false) .extra_warnings(false) .include(WASM3_SOURCE); + + // Add any extra arguments from the environment to the CC command line. + if let Ok(extra_clang_args) = std::env::var("BINDGEN_EXTRA_CLANG_ARGS") { + // Try to parse it with shell quoting. If we fail, make it one single big argument. + if let Some(strings) = shlex::split(&extra_clang_args) { + strings.iter().for_each(|string| { + cfg.flag(string); + }) + } else { + cfg.flag(&extra_clang_args); + }; + } + if cfg!(feature = "wasi") { cfg.define("d_m3HasWASI", None); } + cfg.define( "d_m3Use32BitSlots", if cfg!(feature = "use-32bit-slots") {