summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2019-03-26 14:14:35 +0100
committerGitHub <noreply@github.com>2019-03-26 14:14:35 +0100
commit002cb290c6a54c070efaca191382d65193e2c257 (patch)
treeaa9eeb217676a4aecb5b609e491db9c303ce7f9b
parentb59419a3f4a8277920bce9d6ad3c0597216faa1c (diff)
parent09c299b1dcac566da6dd6ca5769fe1e2868bd068 (diff)
Merge pull request #1543 from emilio/include-path
options: Add an option to opt-out of include path detection.
-rw-r--r--src/lib.rs108
-rw-r--r--src/options.rs7
2 files changed, 65 insertions, 50 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c5bcf494..fb30d35c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1135,6 +1135,12 @@ impl Builder {
self
}
+ /// Whether to detect include paths using clang_sys.
+ pub fn detect_include_paths(mut self, doit: bool) -> Self {
+ self.options.detect_include_paths = doit;
+ self
+ }
+
/// Prepend the enum name to constant or bitfield variants.
pub fn prepend_enum_name(mut self, doit: bool) -> Self {
self.options.prepend_enum_name = doit;
@@ -1504,6 +1510,9 @@ struct BindgenOptions {
/// [1]: https://github.com/rust-lang-nursery/rust-bindgen/issues/528
enable_mangling: bool,
+ /// Whether to detect include paths using clang_sys.
+ detect_include_paths: bool,
+
/// Whether to prepend the enum name to bitfield or constant variants.
prepend_enum_name: bool,
@@ -1638,6 +1647,7 @@ impl Default for BindgenOptions {
objc_extern_crate: false,
block_extern_crate: false,
enable_mangling: true,
+ detect_include_paths: true,
prepend_enum_name: true,
time_phases: false,
record_matches: true,
@@ -1689,69 +1699,67 @@ impl Bindings {
options.build();
- // Filter out include paths and similar stuff, so we don't incorrectly
- // promote them to `-isystem`.
- let clang_args_for_clang_sys = {
- let mut last_was_include_prefix = false;
- options.clang_args.iter().filter(|arg| {
- if last_was_include_prefix {
- last_was_include_prefix = false;
- return false;
- }
+ fn detect_include_paths(options: &mut BindgenOptions) {
+ if !options.detect_include_paths {
+ return;
+ }
- let arg = &**arg;
+ // Filter out include paths and similar stuff, so we don't incorrectly
+ // promote them to `-isystem`.
+ let clang_args_for_clang_sys = {
+ let mut last_was_include_prefix = false;
+ options.clang_args.iter().filter(|arg| {
+ if last_was_include_prefix {
+ last_was_include_prefix = false;
+ return false;
+ }
- // https://clang.llvm.org/docs/ClangCommandLineReference.html
- // -isystem and -isystem-after are harmless.
- if arg == "-I" || arg == "--include-directory" {
- last_was_include_prefix = true;
- return false;
- }
+ let arg = &**arg;
- if arg.starts_with("-I") || arg.starts_with("--include-directory=") {
- return false;
- }
+ // https://clang.llvm.org/docs/ClangCommandLineReference.html
+ // -isystem and -isystem-after are harmless.
+ if arg == "-I" || arg == "--include-directory" {
+ last_was_include_prefix = true;
+ return false;
+ }
- true
- }).cloned().collect::<Vec<_>>()
- };
+ if arg.starts_with("-I") || arg.starts_with("--include-directory=") {
+ return false;
+ }
+
+ true
+ }).cloned().collect::<Vec<_>>()
+ };
- debug!("Trying to find clang with flags: {:?}", clang_args_for_clang_sys);
+ debug!("Trying to find clang with flags: {:?}", clang_args_for_clang_sys);
+
+ let clang = match clang_sys::support::Clang::find(None, &clang_args_for_clang_sys) {
+ None => return,
+ Some(clang) => clang,
+ };
- // TODO: Make this path fixup configurable?
- if let Some(clang) = clang_sys::support::Clang::find(
- None,
- &clang_args_for_clang_sys,
- ) {
debug!("Found clang: {:?}", clang);
- // If --target is specified, assume caller knows what they're doing
- // and don't mess with include paths for them
- let has_target_arg = options
- .clang_args
- .iter()
- .rposition(|arg| arg.starts_with("--target"))
- .is_some();
- if !has_target_arg {
- // Whether we are working with C or C++ inputs.
- let is_cpp = args_are_cpp(&options.clang_args);
- let search_paths = if is_cpp {
- clang.cpp_search_paths
- } else {
- clang.c_search_paths
- };
-
- if let Some(search_paths) = search_paths {
- for path in search_paths.into_iter() {
- if let Ok(path) = path.into_os_string().into_string() {
- options.clang_args.push("-isystem".to_owned());
- options.clang_args.push(path);
- }
+ // Whether we are working with C or C++ inputs.
+ let is_cpp = args_are_cpp(&options.clang_args);
+ let search_paths = if is_cpp {
+ clang.cpp_search_paths
+ } else {
+ clang.c_search_paths
+ };
+
+ if let Some(search_paths) = search_paths {
+ for path in search_paths.into_iter() {
+ if let Ok(path) = path.into_os_string().into_string() {
+ options.clang_args.push("-isystem".to_owned());
+ options.clang_args.push(path);
}
}
}
}
+ detect_include_paths(&mut options);
+
#[cfg(unix)]
fn can_read(perms: &std::fs::Permissions) -> bool {
use std::os::unix::fs::PermissionsExt;
diff --git a/src/options.rs b/src/options.rs
index e9c1b032..64de93cc 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -203,6 +203,9 @@ where
Arg::with_name("no-prepend-enum-name")
.long("no-prepend-enum-name")
.help("Do not prepend the enum name to bitfield or constant variants."),
+ Arg::with_name("no-include-path-detection")
+ .long("no-include-path-detection")
+ .help("Do not try to detect default include paths"),
Arg::with_name("unstable-rust")
.long("unstable-rust")
.help("Generate unstable Rust code (deprecated; use --rust-target instead).")
@@ -447,6 +450,10 @@ where
builder = builder.prepend_enum_name(false);
}
+ if matches.is_present("no-include-path-detection") {
+ builder = builder.detect_include_paths(false);
+ }
+
if matches.is_present("time-phases") {
builder = builder.time_phases(true);
}