Skip to content

Commit 8a60512

Browse files
committed
lib: Do the path fixup inside the library, so users of the library don't have to do this themselves.
1 parent aa05fdf commit 8a60512

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

bindgen/src/main.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,6 @@ pub fn main() {
4242
_ => {}
4343
}
4444

45-
if let Some(clang) = clang_sys::support::Clang::find(None) {
46-
let has_clang_args =
47-
bind_args.iter().rposition(|arg| *arg == "--").is_some();
48-
if !has_clang_args {
49-
bind_args.push("--".to_owned());
50-
}
51-
52-
// If --target is specified, assume caller knows what they're doing and
53-
// don't mess with
54-
// include paths for them
55-
let has_target_arg = bind_args.iter()
56-
.rposition(|arg| arg.starts_with("--target"))
57-
.is_some();
58-
if !has_target_arg {
59-
// TODO: distinguish C and C++ paths? C++'s should be enough, I
60-
// guess.
61-
for path in clang.cpp_search_paths.into_iter() {
62-
if let Ok(path) = path.into_os_string().into_string() {
63-
bind_args.push("-isystem".to_owned());
64-
bind_args.push(path);
65-
}
66-
}
67-
}
68-
}
69-
7045
match builder_from_flags(bind_args.into_iter()) {
7146
Ok((builder, output)) => {
7247
let mut bindings = builder.generate()

libbindgen/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,25 @@ impl<'ctx> Bindings<'ctx> {
509509
-> Result<Bindings<'ctx>, ()> {
510510
let span = span.unwrap_or(DUMMY_SP);
511511

512+
// TODO: Make this path fixup configurable?
513+
if let Some(clang) = clang_sys::support::Clang::find(None) {
514+
// If --target is specified, assume caller knows what they're doing
515+
// and don't mess with include paths for them
516+
let has_target_arg = options.clang_args.iter()
517+
.rposition(|arg| arg.starts_with("--target"))
518+
.is_some();
519+
if !has_target_arg {
520+
// TODO: distinguish C and C++ paths? C++'s should be enough, I
521+
// guess.
522+
for path in clang.cpp_search_paths.into_iter() {
523+
if let Ok(path) = path.into_os_string().into_string() {
524+
options.clang_args.push("-isystem".to_owned());
525+
options.clang_args.push(path);
526+
}
527+
}
528+
}
529+
}
530+
512531
if let Some(h) = options.input_header.as_ref() {
513532
options.clang_args.push(h.clone())
514533
}

0 commit comments

Comments
 (0)