diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-07-27 18:33:18 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-07-27 18:33:18 +0200 |
commit | 4312cf509c15bde697bce12562f20d56e1e9e951 (patch) | |
tree | c877884685f1acd84a1b1a754a0a714f165e5ed1 | |
parent | 331862adaf29c3a73db4156fd346b7755123fa3e (diff) |
lib: Filter out include paths when looking for clang paths.
-rw-r--r-- | src/lib.rs | 29 |
1 files changed, 28 insertions, 1 deletions
@@ -1162,8 +1162,35 @@ impl<'ctx> Bindings<'ctx> { 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; + } + + let arg = &**arg; + + // 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; + } + + if arg.starts_with("-I") || arg.starts_with("--include-directory=") { + return false; + } + + true + }).cloned().collect::<Vec<_>>() + }; + // TODO: Make this path fixup configurable? - if let Some(clang) = clang_sys::support::Clang::find(None, &options.clang_args) { + if let Some(clang) = clang_sys::support::Clang::find(None, &clang_args_for_clang_sys) { // 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 |