Skip to content

Commit 9bee78d

Browse files
smurfdemilio
authored andcommitted
BINDGEN_EXTRA_CLANG_ARGS for dump_preprocessed_input.
Fixes rust-lang#1723
1 parent e180d14 commit 9bee78d

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/lib.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,20 @@ pub fn builder() -> Builder {
232232
Default::default()
233233
}
234234

235+
fn get_extra_clang_args() -> Vec<String> {
236+
// Add any extra arguments from the environment to the clang command line.
237+
let extra_clang_args =
238+
match get_target_dependent_env_var("BINDGEN_EXTRA_CLANG_ARGS") {
239+
None => return vec![],
240+
Some(s) => s,
241+
};
242+
// Try to parse it with shell quoting. If we fail, make it one single big argument.
243+
if let Some(strings) = shlex::split(&extra_clang_args) {
244+
return strings;
245+
}
246+
extra_clang_args
247+
}
248+
235249
impl Builder {
236250
/// Generates the command line flags use for creating `Builder`.
237251
pub fn command_line_flags(&self) -> Vec<String> {
@@ -1453,16 +1467,7 @@ impl Builder {
14531467
/// Generate the Rust bindings using the options built up thus far.
14541468
pub fn generate(mut self) -> Result<Bindings, BindgenError> {
14551469
// Add any extra arguments from the environment to the clang command line.
1456-
if let Some(extra_clang_args) =
1457-
get_target_dependent_env_var("BINDGEN_EXTRA_CLANG_ARGS")
1458-
{
1459-
// Try to parse it with shell quoting. If we fail, make it one single big argument.
1460-
if let Some(strings) = shlex::split(&extra_clang_args) {
1461-
self.options.clang_args.extend(strings);
1462-
} else {
1463-
self.options.clang_args.push(extra_clang_args);
1464-
};
1465-
}
1470+
self.options.clang_args.extend(get_extra_clang_args());
14661471

14671472
// Transform input headers to arguments on the clang command line.
14681473
self.options.input_header = self.input_headers.pop();
@@ -1549,6 +1554,10 @@ impl Builder {
15491554
cmd.arg(a);
15501555
}
15511556

1557+
for a in get_extra_clang_args() {
1558+
cmd.arg(a);
1559+
}
1560+
15521561
let mut child = cmd.spawn()?;
15531562

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

0 commit comments

Comments
 (0)