extern crate bindgen;
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;
fn main() {
println!("cargo:rerun-if-changed=baldrapi.h");
let mut bindings = bindgen::builder()
.disable_name_namespacing()
.whitelist_function("env_.*")
.whitelist_function("global_.*")
.whitelist_function("table_.*")
.whitelist_function("funcType_.*")
.whitelist_type("Cranelift.*")
.rustified_enum("BD_.*|Trap|TypeCode|FuncTypeIdDescKind")
.whitelist_type("BD_.*|Trap|TypeCode|FuncTypeIdDescKind")
.header("baldrapi.h")
.clang_args(&[
"-x",
"c++",
"-std=gnu++14",
"-fno-sized-deallocation",
"-DRUST_BINDGEN",
])
.clang_arg("-I../..");
match env::var_os("MOZ_TOPOBJDIR") {
Some(path) => {
let path = PathBuf::from(path).join("js/src/rust/extra-bindgen-flags");
let mut extra_flags = String::new();
File::open(&path)
.expect("Failed to open extra-bindgen-flags file")
.read_to_string(&mut extra_flags)
.expect("Failed to read extra-bindgen-flags file");
let display_path = path.to_str().expect("path is utf8 encoded");
println!("cargo:rerun-if-changed={}", display_path);
let extra_flags: Vec<String> = extra_flags
.split_whitespace()
.map(|s| s.to_owned())
.collect();
for flag in extra_flags {
bindings = bindings.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 out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}