Skip to content

Commit e135131

Browse files
committed
Add features documentation
1 parent 6c3251f commit e135131

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

book/src/build/cargo.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,49 @@ 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 functionality such as compiling
150+
the CXX lib with a different standard.
151+
152+
Features are enabled on the CXX crate for Cargo-based setups, and with compiler
153+
options for non-Cargo setups.
154+
155+
The following features are available, see `[features]` section in [Cargo.toml](https://github.com/dtolnay/cxx/blob/master/Cargo.toml) for a full list:
156+
<table>
157+
<tr><th>feature</th><th>compiler option</th><th>description</th></tr>
158+
<tr><td>c++14</td><td>-std=c++14 (gcc, clang), /std:c++14 (msvc)</td><td>Compile CXX lib with c++14</td></tr>
159+
<tr><td>c++17</td><td>-std=c++17 (gcc, clang), /std:c++17 (msvc)</td><td>Compile CXX lib with c++17</td></tr>
160+
</table>
161+
162+
## Additional C++ standard features
163+
Some addition APIs are available if compiling your code with a newer C++ standard.
164+
165+
Please note, that these additional APIs are automatically enabled in the `cxx.h`
166+
header if your code is compiled with the required minimal C++ standard. They do
167+
not depend on building the actual CXX lib against the newer standard at this time.
168+
169+
<table>
170+
<tr><th>Minimal C++ standard</th><th>Description</th></tr>
171+
<tr><td>c++17</td><td>Enables additional `string_view` APIs for `rust::str` and `rust::String`</td></tr>
172+
</table>
173+
174+
Example to e.g. enable the `string_view` APIs for your code, build at least with C++17:
175+
```rust,noplayground
176+
// build.rs
177+
178+
fn main() {
179+
cxx_build::bridge("src/main.rs") // returns a cc::Build
180+
.file("src/demo.cc")
181+
.flag_if_supported("-std=c++17")
182+
.compile("cxxbridge-demo");
183+
184+
println!("cargo:rerun-if-changed=src/main.rs");
185+
println!("cargo:rerun-if-changed=src/demo.cc");
186+
println!("cargo:rerun-if-changed=include/demo.h");
187+
}
188+
```
189+
147190
<br><br><br>
148191
149192
# Advanced features

0 commit comments

Comments
 (0)