CXX: Safe interoperability between Rust and C++
Safe FFI library for calling C++ from Rust and vice versa with zero-overhead bindings via code generation.
Learn more about CXX
CXX is a foreign function interface (FFI) library that facilitates safe interoperability between Rust and C++ codebases. It works by defining FFI boundaries within Rust modules using a bridge macro, then performing static analysis on both sides to ensure type safety and ABI compatibility. The library uses dual code generators - a Rust procedural macro and a C++ code generator - to emit the necessary extern "C" signatures and static assertions. CXX supports native types from both languages including Rust's String/Vec/Box and C++'s std::string/std::vector/std::unique_ptr, making it suitable for integrating existing C++ libraries into Rust applications or vice versa.
Static Safety Analysis
Performs compile-time verification of FFI boundaries to uphold both Rust's and C++'s type system invariants. Uses static assertions to ensure signature accuracy between languages.
Zero-Overhead Bindings
Generates ABI-compatible signatures without runtime checks, memory allocation, copying, or serialization. Operates at native performance levels.
Native Type Support
Provides built-in bindings for standard library types from both languages with idiomatic APIs. Supports complex types like smart pointers and containers across the FFI boundary.
#[cxx::bridge]
mod ffi {
// Shared struct visible to both Rust and C++
struct BlobMetadata {
size: usize,
tags: Vec<String>,
}
extern "Rust" {
// Opaque Rust type
type MultiBuf;
// Rust function callable from C++
fn next_chunk(buf: &mut MultiBuf) -> &[u8];
}
unsafe extern "C++" {
include!("blobstore.h");
// Opaque C++ type
type BlobstoreClient;
// C++ functions callable from Rust
fn new_blobstore_client() -> UniquePtr<BlobstoreClient>;
fn put(&self, parts: &mut MultiBuf) -> u64;
fn metadata(&self, blobid: u64) -> BlobMetadata;
}
}1.0.194
- –Drop Bazel 7 (#1696, #1697)
1.0.193
- –Support for Bazel 9.0.0 (#1693, #1695)
1.0.192
- –Add support for `Vec<Box<T>>` (#1681, )
Top in Developer Tools
Related Repositories
Discover similar tools and frameworks used by developers
Serena
Coding agent toolkit with semantic code retrieval and editing for LLMs via MCP server.
Lima
Linux VM launcher with automatic file sharing, port forwarding, and container engine support.
Cursor AI Downloads
Community repository with download links for all Cursor AI editor versions across Windows, macOS, and Linux.
Keiyoushi Extensions
Extension management for the Keiyoushi multi-source content aggregation platform.
moq
Mock .NET objects using lambda expressions and LINQ.