diff options
author | Ralph Giles <giles@mozilla.com> | 2017-07-05 18:09:02 -0700 |
---|---|---|
committer | Ralph Giles <giles@mozilla.com> | 2017-07-07 22:48:55 -0700 |
commit | 8db2775ba6a81d267b3b355e819bb0d90011506f (patch) | |
tree | 85fe6ac6e7d8763ee1de0b0210348867f526749b | |
parent | 1425ad1bab04c60f955270ded0044fd8d244cd9a (diff) | |
download | servo-8db2775ba6a81d267b3b355e819bb0d90011506f.tar.gz servo-8db2775ba6a81d267b3b355e819bb0d90011506f.zip |
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).
-rw-r--r-- | components/style/build_gecko.rs | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/components/style/build_gecko.rs b/components/style/build_gecko.rs index ec23480c6e3..31717d7ad07 100644 --- a/components/style/build_gecko.rs +++ b/components/style/build_gecko.rs @@ -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"); } |