mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Share bindgen flags globally.
Bug: 1495669 Reviewed-by: emilio,froydnj
This commit is contained in:
parent
2c52210ba7
commit
170909fc31
1 changed files with 4 additions and 47 deletions
|
@ -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<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);
|
||||
}
|
||||
}
|
||||
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<T: Into<String>>(self, file: T) -> Builder {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue