dtolnay

dtolnay/cxx

Rust Apache-2.0 Dev Tools

Safe interop between Rust and C++

6.8k stars
413 forks
active
GitHub +11 / week

6.8k

Stars

413

Forks

194

Open issues

30

Contributors

1.0.197 07 Jul 2026

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.

Dev Tools Library Discovery value: 3/10
Documentation 9/10
Activity 10/10
Community 9/10
Code quality 9/10

Inferred from signals mentioned in the README (tests, CI, type safety) — not a review of the actual code.

Overall score 9/10

AI's overall editorial judgment — not an average of the bars above, can weigh other factors too.

ffi rust-cpp-interop type-safety systems-programming interoperability
Actively maintained Well documented Popular Niche/specialized use case Production ready
Deep Analysis · Based on README and public signals
3w ago

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.

Origin

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

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.

In production

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.

Code analysis
Architecture

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.

Tests

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.

Maintenance

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.

Honest verdict

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

Risks
  • 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.
Prediction

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.

0 found this helpful

Newsletter

Get analyses like this every Monday

Free weekly digest of the most interesting open-source discoveries.

Languages

Rust
85.2%
C++
12.3%
Starlark
1.5%
JavaScript
0.5%
TeX
0.2%
Dockerfile
0.1%
CSS
0.1%
Handlebars
0%

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

Loading…

Contributors over time

Top 100 contributors only — repos with more will plateau at 100.

Loading…

Similar repos

KDAB

KDAB/cxx-qt

CXX-Qt enables safe bidirectional interoperability between Rust and C++ with...

1.5k Rust Dev Tools
getditto

getditto/safer_ffi

safer_ffi is a Rust framework that enables writing FFI (foreign function...

1k Rust Dev Tools
rust-lang

rust-lang/libc

libc provides raw FFI bindings to platform system libraries for Rust, enabling...

2.6k Rust Dev Tools
rust-lang

rust-lang/rust-bindgen

rust-bindgen automatically generates Rust FFI bindings to C and C++ libraries,...

5.2k Rust Dev Tools
rust-lang

rust-lang/cc-rs

cc-rs is a Rust library that enables Cargo build scripts to compile C/C++,...

2.1k Rust Dev Tools
vs. alternatives
rust-lang/rust-bindgen

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.

google/crubit

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.

LaurentMazare/tch-rs

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 (not listed but relevant)

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.