File tree Expand file tree Collapse file tree 7 files changed +21
-9
lines changed Expand file tree Collapse file tree 7 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -568,6 +568,9 @@ where
568
568
Arg :: new ( "merge-extern-blocks" )
569
569
. long ( "merge-extern-blocks" )
570
570
. help ( "Deduplicates extern blocks." ) ,
571
+ Arg :: new ( "cxx" )
572
+ . long ( "cxx" )
573
+ . help ( "Enables parsing C++ headers." ) ,
571
574
Arg :: new ( "V" )
572
575
. long ( "version" )
573
576
. help ( "Prints the version, and exits" ) ,
@@ -1088,5 +1091,9 @@ where
1088
1091
builder = builder. merge_extern_blocks ( true ) ;
1089
1092
}
1090
1093
1094
+ if matches. is_present ( "cxx" ) {
1095
+ builder = builder. cxx ( ) ;
1096
+ }
1097
+
1091
1098
Ok ( ( builder, output, verbose) )
1092
1099
}
Original file line number Diff line number Diff line change 1
- // bindgen-flags: -- -x c++ --std=c++11
1
+ // bindgen-flags: --cxx -- --std=c++11
2
2
3
3
template <typename T>
4
4
struct Foo {
Original file line number Diff line number Diff line change 1
- // bindgen-flags: --rustified-enum ".*" --enable-cxx-namespaces -- -x c++ -std=c++11
1
+ // bindgen-flags: --rustified-enum ".*" --enable-cxx-namespaces --cxx -- -std=c++11
2
2
3
3
namespace foo {
4
4
enum class Bar : unsigned {
Original file line number Diff line number Diff line change 1
- // bindgen-flags: --rustified-enum '.*Rustified.*' --constified-enum-module '.*Module.*' -- -x c++ --std=c++14
1
+ // bindgen-flags: --rustified-enum '.*Rustified.*' --constified-enum-module '.*Module.*' --cxx -- --std=c++14
2
2
3
3
// Constified is default, so no flag for that.
4
4
Original file line number Diff line number Diff line change 1
- // bindgen-flags: --raw-line '#![cfg(feature = "nightly")]' --rust-target 1.33 -- -x c++ -std=c++11
1
+ // bindgen-flags: --raw-line '#![cfg(feature = "nightly")]' --rust-target 1.33 --cxx -- -std=c++11
2
2
3
3
#pragma pack(1)
4
4
Original file line number Diff line number Diff line change @@ -1323,6 +1323,12 @@ impl Builder {
1323
1323
self
1324
1324
}
1325
1325
1326
+ /// Tell `clang` that the input files are `c++` files.
1327
+ #[ inline]
1328
+ pub fn cxx ( self ) -> Builder {
1329
+ self . clang_args ( [ "-x" , "c++" ] )
1330
+ }
1331
+
1326
1332
/// Enable detecting must_use attributes on C functions.
1327
1333
///
1328
1334
/// This is quite slow in some cases (see #1465), so it's disabled by
Original file line number Diff line number Diff line change @@ -7,9 +7,8 @@ be nowhere near as nice as using them in C++. You will have to manually call
7
7
constructors, destructors, overloaded operators, etc yourself.
8
8
9
9
When passing in header files, the file will automatically be treated as C++ if
10
- it ends in ` .hpp ` . If it doesn't, adding ` -x c++ ` clang args can be used to
11
- force C++ mode. You probably also want to use ` -std=c++14 ` or similar clang args
12
- as well.
10
+ it ends in ` .hpp ` . If it doesn't, adding the ` --cxx ` flag will force C++ mode.
11
+ You probably also want to use the clang arg ` -std=c++14 ` or similar as well.
13
12
14
13
You pretty much ** must** use [ allowlisting] ( ./allowlisting.md ) when working
15
14
with C++ to avoid pulling in all of the ` std::.* ` types, many of which ` bindgen `
@@ -71,8 +70,8 @@ cannot translate into Rust:
71
70
generate undefined behaviour. See
72
71
[ the tracking issue for exceptions] ( https://github.com/rust-lang/rust-bindgen/issues/1208 )
73
72
for more details.
74
-
73
+
75
74
* Return value optimization. C++ compilers will in certain circumstances optimize functions
76
75
returning a struct type value to instead take an extra hidden argument that refers
77
76
to the return value struct. ` bindgen ` cannot necessarily know about this optimization and
78
- thus at present ` bindgen ` -interfaces for these kinds of functions are invalid.
77
+ thus at present ` bindgen ` -interfaces for these kinds of functions are invalid.
You can’t perform that action at this time.
0 commit comments