From 170909fc31157ec768dfe53a37fb7d3b60e5d26d Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 9 Oct 2018 15:01:52 +0200 Subject: [PATCH] style: Share bindgen flags globally. Bug: 1495669 Reviewed-by: emilio,froydnj --- components/style/build_gecko.rs | 51 +++------------------------------ 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/components/style/build_gecko.rs b/components/style/build_gecko.rs index c8e886c4b29..9db123a422f 100644 --- a/components/style/build_gecko.rs +++ b/components/style/build_gecko.rs @@ -58,22 +58,10 @@ mod bindings { }; static ref BUILD_CONFIG: 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_os("MOZ_TOPOBJDIR").unwrap()) .join("layout/style/bindgen.toml"); read_config(&path) }; - static ref TARGET_INFO: HashMap = { - 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); - } - } - result - }; static ref INCLUDE_RE: Regex = Regex::new(r#"#include\s*"(.+?)""#).unwrap(); static ref DISTDIR_PATH: PathBuf = { let path = PathBuf::from(env::var_os("MOZ_DIST").unwrap()); @@ -145,35 +133,6 @@ mod bindings { fn mutable_borrowed_type(self, ty: &str) -> Builder; } - fn add_clang_args(mut builder: Builder, config: &Table, matched_os: &mut bool) -> Builder { - fn add_args(mut builder: Builder, values: &[toml::Value]) -> Builder { - for item in values.iter() { - builder = builder.clang_arg(item.as_str().expect("Expect string in list")); - } - builder - } - for (k, v) in config.iter() { - if k == "args" { - builder = add_args(builder, v.as_array().unwrap().as_slice()); - continue; - } - let equal_idx = k.find('=').expect(&format!("Invalid key: {}", k)); - let (target_type, target_value) = k.split_at(equal_idx); - if TARGET_INFO[target_type] != target_value[1..] { - continue; - } - if target_type == "os" { - *matched_os = true; - } - builder = match *v { - toml::Value::Table(ref table) => add_clang_args(builder, table, matched_os), - toml::Value::Array(ref array) => add_args(builder, array), - _ => panic!("Unknown type"), - }; - } - builder - } - impl BuilderExt for Builder { fn get_initial_builder() -> Builder { use bindgen::RustTarget; @@ -207,16 +166,14 @@ mod bindings { 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"); + let extra_bindgen_flags = build_config["args"].as_array().unwrap().as_slice(); + for item in extra_bindgen_flags.iter() { + builder = builder.clang_arg(item.as_str().expect("Expect string in list")); } + builder } fn include>(self, file: T) -> Builder {