Skip to content

Commit

Permalink
Merge pull request #1306 from google/more-cpp-version-notes-tests
Browse files Browse the repository at this point in the history
Further documentation on C++ versions.
  • Loading branch information
adetaylor authored Jun 27, 2023
2 parents 907b2ef + 1b68eb0 commit 2743df8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions book/src/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,14 @@ flowchart TB
```

This interop inevitably involves lots of fiddly small functions. It's likely to perform far better if you can achieve cross-language link-time-optimization (LTO). [This issue](https://github.com/dtolnay/cxx/issues/371) may give some useful hints - see also all the build-related help in [the cxx manual](https://cxx.rs/) which all applies here too.

## C++ versions and other compiler command-line flags

The code generated by cxx and autocxx requires C++ 14, so it's not possible to use an earlier version of C++ than that.

To use a later version, you need to:

* Build the generated code with a later C++ version, for example using the clang argument `-std=c++17`. If you're using autocxx's cargo support, then you would do this by calling methods on the returned `cc::Build` object, for instance [`flag_if_supported`](https://docs.rs/cc/latest/cc/struct.Build.html#method.flag_if_supported).
* _Also_ give similar directives to the C++ parsing which happens _within_ autocxx (specifically, by autocxx's version of bindgen). To do that, use [`Builder::extra_clang_args`](https://docs.rs/autocxx-engine/latest/autocxx_engine/struct.Builder.html#method.extra_clang_args).

The same applies with the command-line `autocxx_gen` support - you'll need to pass such extra compiler options to `autocxx_gen` and also use them when building the generated C++ code.

0 comments on commit 2743df8

Please sign in to comment.