Skip to content

Commit

Permalink
Bug 1549792: Display flags for baldrapi.h binding generation on failu…
Browse files Browse the repository at this point in the history
…re; r=froydnj

This change makes cranelift's use of bindgen more consistent with stylo's.

Differential Revision: https://phabricator.services.mozilla.com/D30238
  • Loading branch information
bnjbvr committed Dec 16, 2019
1 parent 10845ec commit 9d85522
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions js/src/wasm/cranelift/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_.*")
Expand Down Expand Up @@ -70,17 +70,25 @@ fn main() {
.map(|s| s.to_owned())
.collect();
for flag in extra_flags {
bindings = bindings.clang_arg(flag);
generator = generator.clang_arg(flag);
}
}
None => {
println!("cargo:warning=MOZ_TOPOBJDIR should be set by default, otherwise the build is not guaranted to finish.");
}
}

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());
Expand Down

0 comments on commit 9d85522

Please sign in to comment.