mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Read bindgen flags from a generated file.
Bindgen needs some build-specific flags, like the -isysroot passed to clang for the C++ compilation. Try to read these from $objdir/layout/style/bindgen.toml which is created by the Firefox build system, and merge them into the config. See also [Gecko bug 1368083](https://bugzilla.mozilla.org/show_bug.cgi?id=1368083).
This commit is contained in:
parent
1425ad1bab
commit
8db2775ba6
1 changed files with 36 additions and 21 deletions
|
@ -61,31 +61,44 @@ mod bindings {
|
|||
}
|
||||
}
|
||||
|
||||
fn read_config(path: &PathBuf) -> toml::Table {
|
||||
println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
|
||||
update_last_modified(&path);
|
||||
|
||||
let mut contents = String::new();
|
||||
File::open(path).expect("Failed to open config file")
|
||||
.read_to_string(&mut contents).expect("Failed to read config file");
|
||||
let mut parser = toml::Parser::new(&contents);
|
||||
if let Some(result) = parser.parse() {
|
||||
result
|
||||
} else {
|
||||
use std::fmt::Write;
|
||||
let mut reason = String::from("Failed to parse config file:");
|
||||
for err in parser.errors.iter() {
|
||||
let parsed = &contents[..err.lo];
|
||||
write!(&mut reason, "\n* line {} column {}: {}",
|
||||
parsed.lines().count(),
|
||||
parsed.lines().last().map_or(0, |l| l.len()),
|
||||
err).unwrap();
|
||||
}
|
||||
panic!(reason)
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref CONFIG: toml::Table = {
|
||||
// Load Gecko's binding generator config from the source tree.
|
||||
let path = PathBuf::from(env::var("MOZ_SRC").unwrap())
|
||||
.join("layout/style/ServoBindings.toml");
|
||||
println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
|
||||
update_last_modified(&path);
|
||||
|
||||
let mut contents = String::new();
|
||||
File::open(path).expect("Failed to open config file")
|
||||
.read_to_string(&mut contents).expect("Failed to read config file");
|
||||
let mut parser = toml::Parser::new(&contents);
|
||||
if let Some(result) = parser.parse() {
|
||||
result
|
||||
} else {
|
||||
use std::fmt::Write;
|
||||
let mut reason = String::from("Failed to parse config file:");
|
||||
for err in parser.errors.iter() {
|
||||
let parsed = &contents[..err.lo];
|
||||
write!(&mut reason, "\n* line {} column {}: {}",
|
||||
parsed.lines().count(),
|
||||
parsed.lines().last().map_or(0, |l| l.len()),
|
||||
err).unwrap();
|
||||
}
|
||||
panic!(reason)
|
||||
}
|
||||
read_config(&path)
|
||||
};
|
||||
static ref BUILD_CONFIG: toml::Table = {
|
||||
// Load build-specific config overrides.
|
||||
// FIXME: We should merge with CONFIG above instead of
|
||||
// forcing callers to do it.
|
||||
let path = PathBuf::from(env::var("MOZ_TOPOBJDIR").unwrap())
|
||||
.join("layout/style/bindgen.toml");
|
||||
read_config(&path)
|
||||
};
|
||||
static ref TARGET_INFO: HashMap<String, String> = {
|
||||
const TARGET_PREFIX: &'static str = "CARGO_CFG_TARGET_";
|
||||
|
@ -213,6 +226,8 @@ mod bindings {
|
|||
let mut matched_os = false;
|
||||
let build_config = CONFIG["build"].as_table().expect("Malformed config file");
|
||||
builder = add_clang_args(builder, build_config, &mut matched_os);
|
||||
let build_config = BUILD_CONFIG["build"].as_table().expect("Malformed config file");
|
||||
builder = add_clang_args(builder, build_config, &mut matched_os);
|
||||
if !matched_os {
|
||||
panic!("Unknown platform");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue