CXX is a library that provides safe foreign function interface between Rust and C++.
The core problem CXX solves is that traditional FFI approaches using bindgen or cbindgen generate unsafe C-style bindings that create many opportunities for errors. CXX instead defines FFI signatures for both sides of the boundary together in a single Rust module, allowing it to perform static analysis on types and function signatures to uphold both Rust's and C++'s invariants. Code generators then emit the appropriate extern "C" signatures with static assertions to verify correctness at build time. The resulting FFI operates at zero or negligible overhead without copying, serialization, memory allocation, or runtime checks.
A key distinguishing feature is that CXX allows FFI signatures to use native types from either language directly—Rust's String, Box, and Vec alongside C++'s std::string, std::unique_ptr, and std::vector—in any combination. The library provides builtin bindings for standard library types so that method calls are translated idiomatically; for instance, calling len() on a C++ string from Rust invokes the C++ size() member function. This approach means the Rust side of an FFI boundary can remain entirely safe code, shifting the audit burden to the C++ side alone rather than requiring verification of unsafe Rust bindings.
CXX suits projects that need to integrate existing C++ codebases with Rust or gradually migrate between the languages while maintaining type safety guarantees. It requires rustc 1.88 or newer and C++11 or later. The tool integrates with Cargo-managed builds through a procedural macro and build script, and provides a command-line tool for other build systems like Bazel or Buck.
Development activity shows consistent maintenance with regular releases and active CI workflows. The project maintains comprehensive documentation including a tutorial and reference material at its dedicated website. The codebase demonstrates attention to compiler compatibility and build system flexibility across different project configurations.