Safe interop between Rust and C++
6.8k
Stars
413
Forks
194
Open issues
30
Contributors
AI Analysis
CXX is a Rust library that enables safe, zero-overhead FFI (foreign function interface) between Rust and C++, allowing developers to call C++ code from Rust and vice versa without the unsafe pitfalls of traditional bindgen-generated bindings. It specializes in projects that need to integrate with existing C++ codebases or libraries, serving systems programmers, embedded developers, and teams maintaining polyglot Rust/C++ systems who require both safety guarantees and performance.
Inferred from signals mentioned in the README (tests, CI, type safety) — not a review of the actual code.
AI's overall editorial judgment — not an average of the bars above, can weigh other factors too.
CXX brings type-safe, zero-overhead Rust/C++ interop with static FFI boundary enforcement
CXX solves the long-standing problem of safely calling across the Rust/C++ boundary without resorting to raw unsafe C-style bindings. It targets Rust developers integrating with existing C++ codebases — and C++ teams adopting Rust incrementally. Rather than generating raw unsafe extern blocks, CXX enforces type safety at the FFI boundary statically, supports idiomatic types from both languages (std::string, Vec, UniquePtr, etc.), and operates at zero overhead. It is maintained by dtolnay, one of Rust's most prolific and respected library authors, and has broad real-world usage in production Rust/C++ hybrid projects.
Created in late 2019 by David Tolnay, CXX emerged as the Rust ecosystem began serious integration with C++ at companies like Meta, Google, and others. It grew alongside increased industry interest in incrementally introducing Rust into C++ codebases.
Growth was driven by industry momentum around Rust adoption in systems software — particularly at large tech companies with substantial C++ codebases. Stars grew steadily rather than virally, suggesting organic adoption by practitioners solving real integration problems rather than hype-driven attention. Recent star velocity (1/week) reflects a mature, widely-known project rather than active discovery phase.
CXX is used in production at Meta (via Folly/C++ integrations), in the Android platform codebase, and in various open-source Rust projects that wrap C++ libraries. It is referenced in official Rust documentation and ecosystem guides for C++ interop. Crates.io download counts are likely substantial given its role in the ecosystem, though exact figures are not available from the provided metadata.
Appears to use a proc-macro (#[cxx::bridge]) to parse a shared FFI module definition at compile time, then generates both Rust-side and C++-side binding code. Likely uses static assertions on the C++ side to verify ABI correctness. Supports Cargo-based builds via cxx-build and non-Cargo build systems (Bazel, Buck) via a CLI code generator tool. The design separates concerns cleanly: one definition, two generated outputs.
Not documented in README, but the presence of a CI badge and active maintenance by dtolnay — known for high-quality Rust libraries — suggests robust testing. The demo directory provides at minimum an integration-level runnable example.
Last push was 2026-05-31, approximately 3 weeks before evaluation date — actively maintained. dtolnay has a strong track record of long-term library stewardship. The project has been maintained for over 6 years with consistent activity.
ADOPT IF: you are integrating Rust into an existing C++ codebase and need safe, idiomatic bidirectional interop with native type support and build system flexibility. AVOID IF: you only need thin C-style bindings to a C library — bindgen is simpler for that use case — or if your team is unwilling to write explicit bridge module definitions. MONITOR IF: you are watching Google's Crubit for a more automated alternative that may reduce the manual definition overhead CXX currently requires.
Independent dimensions
Mainstream potential
6/10
Technical importance
9/10
Adoption evidence
7/10
- Requires explicit manual bridge definitions for every FFI boundary — increases upfront authoring cost compared to auto-generation tools, which may slow adoption in teams with large existing C++ APIs.
- C++ template types and complex metaprogramming patterns are difficult or impossible to represent in the bridge module, requiring workarounds or wrapper types on the C++ side.
- The project depends heavily on a single maintainer (dtolnay). While he has a strong track record, bus-factor risk is a real concern for production-critical infrastructure.
- Build system integration beyond Cargo (Bazel, Buck, CMake) requires extra setup effort and the ecosystem around non-Cargo CXX usage is less documented and less tested in the open.
- As Rust/C++ interop tooling evolves (e.g., Crubit maturing, potential stdlib-level support), the landscape may shift and today's best practice could change.
CXX is likely to remain the practical default for safe Rust/C++ interop in the medium term. Incremental improvements will continue; displacement would require a more automated tool reaching similar safety guarantees.
Explore similar
Newsletter
Get analyses like this every Monday
Free weekly digest of the most interesting open-source discoveries.
Languages
Information
- Website
- https://cxx.rs
- Language
- Rust
- License
- Apache-2.0
- Last updated
- 8h ago
- Created
- 80mo ago
- Analyzed with
- anthropic/claude-haiku-4-5
Stars over time
Contributors over time
Top 100 contributors only — repos with more will plateau at 100.
Open issues
Top contributors
Similar repos
rust-lang/rust-bindgen
rust-bindgen automatically generates Rust FFI bindings to C and C++ libraries,...
| Repository | Stars | Week Δ | Language | Score | Updated |
|---|---|---|---|---|---|
|
|
6.8k | +11 | Rust | 9/10 | 8h ago |
|
|
1.5k | — | Rust | 8/10 | 4d ago |
|
|
1k | — | Rust | 8/10 | 2mo ago |
|
|
2.6k | — | Rust | 8/10 | 8h ago |
|
|
5.2k | — | Rust | 8/10 | 3d ago |
|
|
2.1k | — | Rust | 8/10 | 9h ago |
bindgen auto-generates unsafe Rust FFI from C/C++ headers — lower friction to start but produces unsafe bindings that require careful auditing. CXX requires explicit bridge definitions but guarantees safety invariants. They are complementary: bindgen for C-style interop, CXX for deep Rust/C++ integration.
Crubit is Google's more automated approach to Rust/C++ interop, aiming to generate bindings with less manual definition. It is newer, less mature, and more tightly coupled to specific build systems. CXX has broader build system support and a larger adoption base today.
tch-rs is a domain-specific Rust binding to LibTorch (C++) — not a general interop tool. It likely uses bindgen or manual FFI internally. Not a direct competitor to CXX; listed for context only.
cbindgen generates C headers from Rust code for C/C++ consumption — the reverse direction of bindgen. CXX handles bidirectional interop in a single unified definition, making it more suitable for tightly coupled Rust/C++ codebases.