Skip to content

Commit 5e49ce9

Browse files
Sander MaijersSander Maijers
Sander Maijers
authored and
Sander Maijers
committed
Check for more common C++ header file extensions
Also, perform `clang` parameter check earlier. If that results in `is_cpp == true`, the later `|=` operations could be elided.
1 parent a09a8ff commit 5e49ce9

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/lib.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,12 @@ impl Builder {
11111111
/// issues. The resulting file will be named something like `__bindgen.i` or
11121112
/// `__bindgen.ii`
11131113
pub fn dump_preprocessed_input(&self) -> io::Result<()> {
1114+
fn check_is_cpp(name_file: &str) -> bool {
1115+
name_file.ends_with(".hpp") || name_file.ends_with(".hxx")
1116+
|| name_file.ends_with(".hh")
1117+
|| name_file.ends_with(".h++")
1118+
}
1119+
11141120
let clang = clang_sys::support::Clang::find(None, &[]).ok_or_else(|| {
11151121
io::Error::new(io::ErrorKind::Other, "Cannot find clang executable")
11161122
})?;
@@ -1120,11 +1126,13 @@ impl Builder {
11201126
let mut wrapper_contents = String::new();
11211127

11221128
// Whether we are working with C or C++ inputs.
1123-
let mut is_cpp = false;
1129+
let mut is_cpp = self.options.clang_args.windows(2).any(|w| {
1130+
w[0] == "-x=c++" || w[1] == "-x=c++" || w == &["-x", "c++"]
1131+
});
11241132

11251133
// For each input header, add `#include "$header"`.
11261134
for header in &self.input_headers {
1127-
is_cpp |= header.ends_with(".hpp");
1135+
is_cpp |= check_is_cpp(header);
11281136

11291137
wrapper_contents.push_str("#include \"");
11301138
wrapper_contents.push_str(header);
@@ -1134,18 +1142,14 @@ impl Builder {
11341142
// For each input header content, add a prefix line of `#line 0 "$name"`
11351143
// followed by the contents.
11361144
for &(ref name, ref contents) in &self.input_header_contents {
1137-
is_cpp |= name.ends_with(".hpp");
1145+
is_cpp |= check_is_cpp(name);
11381146

11391147
wrapper_contents.push_str("#line 0 \"");
11401148
wrapper_contents.push_str(name);
11411149
wrapper_contents.push_str("\"\n");
11421150
wrapper_contents.push_str(contents);
11431151
}
11441152

1145-
is_cpp |= self.options.clang_args.windows(2).any(|w| {
1146-
w[0] == "-x=c++" || w[1] == "-x=c++" || w == &["-x", "c++"]
1147-
});
1148-
11491153
let wrapper_path = PathBuf::from(if is_cpp {
11501154
"__bindgen.cpp"
11511155
} else {

0 commit comments

Comments
 (0)