#build-dependencies #cpp

build cxx-build

C++ code generator for integrating cxx crate into a Cargo build

195 stable releases

1.0.194 Jan 21, 2026
1.0.192 Dec 16, 2025
1.0.190 Nov 28, 2025
1.0.161 Jul 19, 2025
0.3.4 May 22, 2020

#24 in Build Utils

Download history 538874/week @ 2025-10-21 545564/week @ 2025-10-28 559965/week @ 2025-11-04 502040/week @ 2025-11-11 565076/week @ 2025-11-18 359639/week @ 2025-11-25 418253/week @ 2025-12-02 426664/week @ 2025-12-09 433586/week @ 2025-12-16 219322/week @ 2025-12-23 237142/week @ 2025-12-30 451712/week @ 2026-01-06 458277/week @ 2026-01-13 486245/week @ 2026-01-20 469519/week @ 2026-01-27 541284/week @ 2026-02-03

2,031,894 downloads per month
Used in 597 crates (206 directly)

MIT/Apache

410KB
11K SLoC

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

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

// build.rs

fn main() {
    cxx_build::bridge("src/main.rs")
        .file("src/demo.cc")
        .std("c++11")
        .compile("cxxbridge-demo");

    println!("cargo:rerun-if-changed=src/demo.cc");
    println!("cargo:rerun-if-changed=include/demo.h");
}

A runnable working setup with this build script is shown in the demo directory of https://github.com/dtolnay/cxx.


Alternatives

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/main.rs --header > path/to/mybridge.h
$ cxxbridge src/main.rs > path/to/mybridge.cc

Dependencies

~2.6–5.5MB
~98K SLoC