Crate cxx_build

source ·
Expand description

The CXX code generator for constructing and compiling C++ code.

This is intended to be used from Cargo build scripts to execute CXX’s C++ code generator, set up any additional compiler flags depending on the use case, and make the C++ compiler invocation.


Example of a canonical Cargo build script that builds a CXX bridge:


fn main() {


A runnable working setup with this build script is shown in the demo directory of


For use in non-Cargo builds like Bazel or Buck, CXX provides an alternate way of invoking the C++ code generator as a standalone command line tool. The tool is packaged as the cxxbridge-cmd crate.

$ cargo install cxxbridge-cmd  # or build it from the repo

$ cxxbridge src/ --header > path/to/mybridge.h
$ cxxbridge src/ > path/to/


  • Build configuration. See CFG.


  • Global configuration of the current build.


  • This returns a cc::Build on which you should continue to set up any additional source files or compiler flags, and lastly call its compile method to execute the C++ build.
  • cxx_build::bridge but for when more than one file contains a #[cxx::bridge] module.