Bug 1751331 - Use the mozbuild crate in cranelift. r=rhunt

Differential Revision: https://phabricator.services.mozilla.com/D136561
This commit is contained in:
Mike Hommey 2022-01-25 09:03:03 +00:00
parent 47b241bdee
commit a7254d5105
3 changed files with 22 additions and 27 deletions

1
Cargo.lock generated
View file

@ -344,6 +344,7 @@ dependencies = [
"cranelift-wasm",
"env_logger",
"log",
"mozbuild",
"smallvec",
]

View file

@ -17,6 +17,7 @@ smallvec = "1.0"
[build-dependencies]
bindgen = {version = "0.56", default-features = false} # disable `logging` to reduce code size
mozbuild = "0.1"
[features]
default = ['cranelift-codegen/std']

View file

@ -55,38 +55,31 @@ fn main() {
])
.clang_arg("-I../..");
match env::var_os("MOZ_TOPOBJDIR") {
Some(objdir) => {
let generated_src = PathBuf::from(objdir).join("js/src");
let path = generated_src.clone().join("rust/extra-bindgen-flags");
let generated_src = mozbuild::TOPOBJDIR.join("js/src");
let path = generated_src.clone().join("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 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 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 {
generator = generator.clang_arg(flag);
}
generator = generator.clang_arg(format!(
"-I{}",
generated_src.to_str().expect("path is utf8 encoded")
));
}
None => {
println!("cargo:warning=MOZ_TOPOBJDIR should be set by default, otherwise the build is not guaranted to finish.");
}
let extra_flags: Vec<String> = extra_flags
.split_whitespace()
.map(|s| s.to_owned())
.collect();
for flag in extra_flags {
generator = generator.clang_arg(flag);
}
generator = generator.clang_arg(format!(
"-I{}",
generated_src.to_str().expect("path is utf8 encoded")
));
let command_line_opts = generator.command_line_flags();
// In case of error, bindgen prints to stderr, and the yielded error is the empty type ().