A safe, zero-overhead FFI bridge for calling C++ code from Rust and Rust code from C++.
CXX is a library that provides a safe Foreign Function Interface (FFI) mechanism for interoperability between Rust and C++ code. It eliminates the risks associated with unsafe C-style bindings by enabling developers to call functions and use native types from either language while maintaining 100% safety on the Rust side. The library performs compile-time checks on FFI boundaries to uphold language invariants and operates with zero overhead.
Rust developers who need to integrate with existing C++ codebases or libraries, and C++ developers looking to incorporate Rust components into their projects while ensuring memory safety. It's particularly valuable for teams maintaining mixed-language systems where safety and performance are critical.
Developers choose CXX over alternatives like bindgen or cbindgen because it guarantees safety on the Rust side without runtime overhead, using static analysis to prevent common FFI errors. Its unique selling point is providing idiomatic type support (like Rust's String/Vec and C++'s std::string/std::vector) while maintaining a zero-cost abstraction, unlike serialization-based approaches.
Safe interop between Rust and C++
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
CXX ensures 100% safe Rust code by performing static analysis on FFI boundaries, as stated in the README, eliminating the need to audit the Rust side for memory safety issues.
Operates without copying, serialization, or runtime checks, providing performance identical to hand-written unsafe code, as emphasized in the overview section.
Allows seamless use of native types like Rust's String and C++'s std::string, with ABI-compatible mappings detailed in the builtin types table for natural APIs.
Supports both Cargo-based builds via a build script and non-Cargo setups with a command-line tool, as described in the setup sections, accommodating various project structures.
Missing support for common types like Rust's Option, HashMap, and C++'s std::map, as admitted in the 'Remaining work' section, which can block certain use cases.
Requires function signatures to be typed out twice—once in the implementation and once in the bridge module—increasing maintenance burden, as noted in the comparison with bindgen.
Intentionally opinionated and may not handle arbitrary FFI signatures, forcing developers to work around limitations or fall back to unsafe bindings for edge cases.
Integrating with build systems like Bazel requires manual steps using the command-line tool, which can be error-prone compared to integrated Cargo workflows.