Skip to content

Commit 6b21505

Browse files
committed
add --cxx flag
1 parent 9677e41 commit 6b21505

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

book/src/cpp.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ be nowhere near as nice as using them in C++. You will have to manually call
77
constructors, destructors, overloaded operators, etc yourself.
88

99
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.
1312

1413
You pretty much **must** use [allowlisting](./allowlisting.md) when working
1514
with C++ to avoid pulling in all of the `std::.*` types, many of which `bindgen`
@@ -71,8 +70,8 @@ cannot translate into Rust:
7170
generate undefined behaviour. See
7271
[the tracking issue for exceptions](https://github.com/rust-lang/rust-bindgen/issues/1208)
7372
for more details.
74-
73+
7574
* Return value optimization. C++ compilers will in certain circumstances optimize functions
7675
returning a struct type value to instead take an extra hidden argument that refers
7776
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.

src/options.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,9 @@ where
518518
Arg::new("sort-semantically")
519519
.long("sort-semantically")
520520
.help("Enables sorting of code generation in a predefined manner."),
521+
Arg::new("cxx")
522+
.long("cxx")
523+
.help("Enables parsing C++ headers."),
521524
Arg::new("V")
522525
.long("version")
523526
.help("Prints the version, and exits"),
@@ -1007,5 +1010,9 @@ where
10071010
builder = builder.sort_semantically(true);
10081011
}
10091012

1013+
if matches.is_present("cxx") {
1014+
builder = builder.clang_args(["-x", "c++"]);
1015+
}
1016+
10101017
Ok((builder, output, verbose))
10111018
}

tests/headers/dash_language.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// bindgen-flags: -- -x c++ --std=c++11
1+
// bindgen-flags: --cxx -- --std=c++11
22

33
template<typename T>
44
struct Foo {

tests/headers/dupe-enum-variant-in-namespace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
22

33
namespace foo {
44
enum class Bar : unsigned {

tests/headers/empty-enum.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
22

33
// Constified is default, so no flag for that.
44

tests/headers/packed-vtable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
22

33
#pragma pack(1)
44

0 commit comments

Comments
 (0)