Skip to content

Commit

Permalink
BINDGEN_EXTRA_CLANG_ARGS for dump_preprocessed_input.
Browse files Browse the repository at this point in the history
Fixes #1723
  • Loading branch information
smurfd authored and emilio committed Feb 18, 2022
1 parent cd78b65 commit f34e410
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,20 @@ pub fn builder() -> Builder {
Default::default()
}

fn get_extra_clang_args() -> Vec<String> {
// Add any extra arguments from the environment to the clang command line.
let extra_clang_args =
match get_target_dependent_env_var("BINDGEN_EXTRA_CLANG_ARGS") {
None => return vec![],
Some(s) => s,
};
// Try to parse it with shell quoting. If we fail, make it one single big argument.
if let Some(strings) = shlex::split(&extra_clang_args) {
return strings;
}
vec![extra_clang_args]
}

impl Builder {
/// Generates the command line flags use for creating `Builder`.
pub fn command_line_flags(&self) -> Vec<String> {
Expand Down Expand Up @@ -1465,16 +1479,7 @@ impl Builder {
/// Generate the Rust bindings using the options built up thus far.
pub fn generate(mut self) -> Result<Bindings, BindgenError> {
// Add any extra arguments from the environment to the clang command line.
if let Some(extra_clang_args) =
get_target_dependent_env_var("BINDGEN_EXTRA_CLANG_ARGS")
{
// Try to parse it with shell quoting. If we fail, make it one single big argument.
if let Some(strings) = shlex::split(&extra_clang_args) {
self.options.clang_args.extend(strings);
} else {
self.options.clang_args.push(extra_clang_args);
};
}
self.options.clang_args.extend(get_extra_clang_args());

// Transform input headers to arguments on the clang command line.
self.options.input_header = self.input_headers.pop();
Expand Down Expand Up @@ -1561,6 +1566,10 @@ impl Builder {
cmd.arg(a);
}

for a in get_extra_clang_args() {
cmd.arg(a);
}

let mut child = cmd.spawn()?;

let mut preprocessed = child.stdout.take().unwrap();
Expand Down

0 comments on commit f34e410

Please sign in to comment.