Skip to content

issue 1723 #1915

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

Merged
merged 1 commit into from
Feb 18, 2022
Merged
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
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 @@ -1453,16 +1467,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 @@ -1549,6 +1554,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