Skip to content

Commit 0e39721

Browse files
author
bors-servo
authored
Auto merge of rust-lang#860 - emilio:issue-848, r=fitzgen
lib: Filter out include paths when looking for clang paths. Fixes rust-lang#848
2 parents 0fab51e + 05b1550 commit 0e39721

File tree

6 files changed

+78
-3
lines changed

6 files changed

+78
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ name = "bindgen"
1313
readme = "README.md"
1414
repository = "https://github.com/rust-lang-nursery/rust-bindgen"
1515
documentation = "https://docs.rs/bindgen"
16-
version = "0.28.0"
16+
version = "0.29.0"
1717
build = "build.rs"
1818

1919
exclude = [

src/lib.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,8 +1162,35 @@ impl<'ctx> Bindings<'ctx> {
11621162

11631163
options.build();
11641164

1165+
// Filter out include paths and similar stuff, so we don't incorrectly
1166+
// promote them to `-isystem`.
1167+
let clang_args_for_clang_sys = {
1168+
let mut last_was_include_prefix = false;
1169+
options.clang_args.iter().filter(|arg| {
1170+
if last_was_include_prefix {
1171+
last_was_include_prefix = false;
1172+
return false;
1173+
}
1174+
1175+
let arg = &**arg;
1176+
1177+
// https://clang.llvm.org/docs/ClangCommandLineReference.html
1178+
// -isystem and -isystem-after are harmless.
1179+
if arg == "-I" || arg == "--include-directory" {
1180+
last_was_include_prefix = true;
1181+
return false;
1182+
}
1183+
1184+
if arg.starts_with("-I") || arg.starts_with("--include-directory=") {
1185+
return false;
1186+
}
1187+
1188+
true
1189+
}).cloned().collect::<Vec<_>>()
1190+
};
1191+
11651192
// TODO: Make this path fixup configurable?
1166-
if let Some(clang) = clang_sys::support::Clang::find(None, &options.clang_args) {
1193+
if let Some(clang) = clang_sys::support::Clang::find(None, &clang_args_for_clang_sys) {
11671194
// If --target is specified, assume caller knows what they're doing
11681195
// and don't mess with include paths for them
11691196
let has_target_arg = options.clang_args
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
5+
6+
7+
/// This is intended to replace another type, but won't if we treat this include
8+
/// as a system include, because clang doesn't parse comments there.
9+
///
10+
/// See #848.
11+
///
12+
/// <div rustbindgen replaces="nsTArray"></div>
13+
#[repr(C)]
14+
#[derive(Debug, Copy, Clone)]
15+
pub struct nsTArray<T> {
16+
pub m: *mut T,
17+
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
18+
}
19+
impl <T> Default for nsTArray<T> {
20+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
21+
}
22+
extern "C" {
23+
pub fn func() -> *mut nsTArray<::std::os::raw::c_int>;
24+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// bindgen-flags: -- -Itests/headers/issue-848
2+
3+
#include "an-include.h"
4+
5+
extern "C" {
6+
nsTArray<int>* func();
7+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
template<typename T>
2+
class nsTArray {
3+
void* mBuffer;
4+
};
5+
6+
/**
7+
* This is intended to replace another type, but won't if we treat this include
8+
* as a system include, because clang doesn't parse comments there.
9+
*
10+
* See #848.
11+
*
12+
* <div rustbindgen replaces="nsTArray"></div>
13+
*/
14+
template<typename T>
15+
class nsTArray_Simple {
16+
T* m;
17+
};

0 commit comments

Comments
 (0)