diff --git a/xbuild/src/cargo/mod.rs b/xbuild/src/cargo/mod.rs index adb91766..bc6efdab 100644 --- a/xbuild/src/cargo/mod.rs +++ b/xbuild/src/cargo/mod.rs @@ -387,13 +387,24 @@ impl CargoBuild { fn cargo_target_env(&mut self, name: &str, value: &str) { if let Some(triple) = self.triple { let utarget = triple.replace('-', "_"); - let env = format!("CARGO_TARGET_{}_{}", &utarget, name); + let env = format!("CARGO_TARGET_{}_{}", utarget, name); self.cmd.env(env.to_uppercase(), value); } else { self.cmd.env(name, value); } } + /// Configures a cargo target specific environment variable. + fn bindgen_env(&mut self, value: &str) { + if let Some(triple) = self.triple { + let utarget = triple.replace('-', "_"); + let env = format!("BINDGEN_EXTRA_CLANG_ARGS_{}", utarget); + self.cmd.env(env, value); + } else { + self.cmd.env("BINDGEN_EXTRA_CLANG_ARGS", value); + } + } + /// Configures an environment variable for the `cc` crate. fn cc_triple_env(&mut self, name: &str, value: &str) { if let Some(triple) = self.triple { @@ -465,6 +476,7 @@ impl CargoBuild { pub fn exec(mut self) -> Result<()> { self.cargo_target_env("RUSTFLAGS", &self.rust_flags.clone()); + self.bindgen_env(&self.c_flags.clone()); self.cc_triple_env("CFLAGS", &self.c_flags.clone()); // These strings already end with a space if they're non-empty: self.cc_triple_env("CXXFLAGS", &format!("{}{}", self.c_flags, self.cxx_flags));