Bug 1368083 - Read bindgen flags from a generated file. r=emilio
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 build system, and merge them into the config.
MozReview-Commit-ID: 2tpAHnYjJlA
--- a/servo/components/style/build_gecko.rs
+++ b/servo/components/style/build_gecko.rs
@@ -56,41 +56,54 @@ mod bindings {
fn structs_file(build_type: BuildType) -> &'static str {
match build_type {
BuildType::Debug => STRUCTS_DEBUG_FILE,
BuildType::Release => STRUCTS_RELEASE_FILE
}
}
+ 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_";
let mut result = HashMap::new();
for (k, v) in env::vars() {
if k.starts_with(TARGET_PREFIX) {
result.insert(k[TARGET_PREFIX.len()..].to_lowercase(), v);
}
@@ -208,16 +221,18 @@ mod bindings {
if build_type == BuildType::Debug {
builder = builder.clang_arg("-DDEBUG=1").clang_arg("-DJS_DEBUG=1");
}
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");
}
builder
}
fn include<T: Into<String>>(self, file: T) -> Builder {
self.clang_arg("-include").clang_arg(file)
}