Skip to content

Commit 18d9c71

Browse files
committed
Add features documentation
1 parent 3044336 commit 18d9c71

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

book/src/build/cargo.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,46 @@ manifest key][links]* in the Cargo reference.
144144
145145
[links]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key
146146
147+
## Features
148+
149+
CXX provides features to enable additional or alternative APIs.
150+
151+
Features are enabled on the CXX crate for Cargo-based setups, and with compiler
152+
options for non-Cargo setups.
153+
154+
The following features are available, see `[features]` section in [Cargo.toml](https://github.com/dtolnay/cxx/blob/master/Cargo.toml) for a full list:
155+
<table>
156+
<tr><th>feature</th><th>compiler option</th><th>description</th></tr>
157+
<tr><td>c++14</td><td>-std=c++14 (gcc, clang), /std:c++14 (msvc)</td><td>Compile CXX with c++14</td></tr>
158+
<tr><td>c++17</td><td>-std=c++17 (gcc, clang), /std:c++17 (msvc)</td><td>Compile CXX with c++17.
159+
Enables string_view APIs for rust::str and rust::String</td></tr>
160+
</table>
161+
162+
You will have to enable the feature on the CXX crate *as well as* add the
163+
equivalent compiler option to your cargo build.
164+
165+
Example to e.g. enable C++17:
166+
```toml,hidelines
167+
## Cargo.toml
168+
[dependencies]
169+
cxx = { version = "0.4", features = ["c++17"] }
170+
```
171+
172+
```rust,noplayground
173+
// build.rs
174+
175+
fn main() {
176+
cxx_build::bridge("src/main.rs") // returns a cc::Build
177+
.file("src/demo.cc")
178+
.flag_if_supported("-std=c++17")
179+
.compile("cxxbridge-demo");
180+
181+
println!("cargo:rerun-if-changed=src/main.rs");
182+
println!("cargo:rerun-if-changed=src/demo.cc");
183+
println!("cargo:rerun-if-changed=include/demo.h");
184+
}
185+
```
186+
147187
<br><br><br>
148188
149189
# Advanced features

0 commit comments

Comments
 (0)