Skip to content

Commit f34e410

Browse files
smurfdemilio
authored andcommitted
BINDGEN_EXTRA_CLANG_ARGS for dump_preprocessed_input.
Fixes #1723
1 parent cd78b65 commit f34e410

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+
vec![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> {
@@ -1465,16 +1479,7 @@ impl Builder {
14651479
/// Generate the Rust bindings using the options built up thus far.
14661480
pub fn generate(mut self) -> Result<Bindings, BindgenError> {
14671481
// Add any extra arguments from the environment to the clang command line.
1468-
if let Some(extra_clang_args) =
1469-
get_target_dependent_env_var("BINDGEN_EXTRA_CLANG_ARGS")
1470-
{
1471-
// Try to parse it with shell quoting. If we fail, make it one single big argument.
1472-
if let Some(strings) = shlex::split(&extra_clang_args) {
1473-
self.options.clang_args.extend(strings);
1474-
} else {
1475-
self.options.clang_args.push(extra_clang_args);
1476-
};
1477-
}
1482+
self.options.clang_args.extend(get_extra_clang_args());
14781483

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

1569+
for a in get_extra_clang_args() {
1570+
cmd.arg(a);
1571+
}
1572+
15641573
let mut child = cmd.spawn()?;
15651574

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

0 commit comments

Comments
 (0)