diff --git a/js/src/wasm/cranelift/build.rs b/js/src/wasm/cranelift/build.rs index cde4310c8a176..e8442e6876859 100644 --- a/js/src/wasm/cranelift/build.rs +++ b/js/src/wasm/cranelift/build.rs @@ -30,7 +30,7 @@ fn main() { // Tell Cargo to regenerate the bindings if the header file changes. println!("cargo:rerun-if-changed=baldrapi.h"); - let mut bindings = bindgen::builder() + let mut generator = bindgen::builder() .disable_name_namespacing() // We whitelist the Baldr C functions and get the associated types for free. .whitelist_function("env_.*") @@ -70,7 +70,7 @@ fn main() { .map(|s| s.to_owned()) .collect(); for flag in extra_flags { - bindings = bindings.clang_arg(flag); + generator = generator.clang_arg(flag); } } None => { @@ -78,9 +78,17 @@ fn main() { } } - let bindings = bindings - .generate() - .expect("Unable to generate baldrapi.h bindings"); + let command_line_opts = generator.command_line_flags(); + + // In case of error, bindgen prints to stderr, and the yielded error is the empty type (). + let bindings = generator.generate().unwrap_or_else(|_err| { + panic!( + r#"Unable to generate baldrapi.h bindings: +- flags: {} +"#, + command_line_opts.join(" "), + ); + }); // Write the bindings to the $OUT_DIR/bindings.rs file. let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());