summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2018-07-31 05:05:48 +1000
committerGitHub <noreply@github.com>2018-07-31 05:05:48 +1000
commit0f9b272df1ce528f8b4b456ec2bb3583a774123b (patch)
tree93b20e8f3f83b060d9aad775c0dc6e540a651adf /src
parentbb283a26fad11affbbe55bdb98d349e111e98f62 (diff)
parent2a2e7b5f099ef23a3b7f86646c681489aa1e74d4 (diff)
Merge pull request #1351 from Imirsen/master. r=emilio
select cpp or c search paths based on clang args
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 7dd39138..e66ba98c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -94,6 +94,12 @@ use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::sync::Arc;
+fn args_are_cpp(clang_args: &[String]) -> bool {
+ return clang_args
+ .windows(2)
+ .any(|w| w[0] == "-x=c++" || w[1] == "-x=c++" || w == &["-x", "c++"]);
+}
+
/// A type used to indicate which kind of items do we have to generate.
///
/// TODO(emilio): Use `bitflags!`
@@ -1160,9 +1166,7 @@ impl Builder {
let mut wrapper_contents = String::new();
// Whether we are working with C or C++ inputs.
- let mut is_cpp = self.options.clang_args.windows(2).any(|w| {
- w[0] == "-x=c++" || w[1] == "-x=c++" || w == &["-x", "c++"]
- });
+ let mut is_cpp = args_are_cpp(&self.options.clang_args);
// For each input header, add `#include "$header"`.
for header in &self.input_headers {
@@ -1633,8 +1637,17 @@ impl Bindings {
if !has_target_arg {
// TODO: distinguish C and C++ paths? C++'s should be enough, I
// guess.
- if let Some(cpp_search_paths) = clang.cpp_search_paths {
- for path in cpp_search_paths.into_iter() {
+
+ // 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);