Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo: Forward cflags to bindgen via BINDGEN_EXTRA_CLANG_ARGS #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion xbuild/src/cargo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
Expand Down
Loading