cloudflare/workerd-cxx
forked from dtolnay/cxx
Captured source
source ↗cloudflare/workerd-cxx
Description: workerd-cxx is a fork of cxx crate for workerd/edgeworker project
Language: Rust
License: Apache-2.0
Stars: 9
Forks: 3
Open issues: 2
Created: 2024-07-03T14:44:17Z
Pushed: 2026-06-10T15:02:50Z
Default branch: master
Fork: yes
Parent repository: dtolnay/cxx
Archived: no
README:
Workerd-cxx - C++/Rust interop for Cloudflare Workerd
This project is a fork of an excellent [cxx](https://crates.io/crates/cxx) crate for [workerd](https://github.com/cloudflare/workerd) ecosystem.
See [README.md.orig](README.md.orig) and upstream documentation for the original information about cxx crate and its basic features.
This README concerns itself with the differences between the cxx crate and the fork.
Development
Workerd-cxx can be built and consumed only using bazel. See justfile for common commands.
Differences/Features
Safety: kj::Exception integration and panic handling
Generated bridge is fully compatible with KJ exception model:
- C++ code is assumed to always throw and returns
Result. - Rust code returning any
Resultwill convert errors tokj::ExceptionusingDisplay. - Rust code using error type
::cxx::KjErrorcan fully control information in the thrown exception. kj::CanceledExceptioncauses panic with::cxx::CanceledExceptionpayload.- panic with
::cxx::CanceledExceptioncauseskj::CanceledExceptionto be thrown. - any other panic will result in
kj::Exceptionto be thrown.
KJ Smart Pointers Integration
The following smart pointers can be used in ffi layers:
kj::Own- corresponds tokj_rs::KjOwnkj::Rc- corresponds tokj_rs::KjRckj::Arc- corresponds tokj_rs::KjArc
KJ Data Structures Integration
kj::Maybe- corresponds tokj_rs::KjMaybe.kj::Date- corresponds tokj_rs::KjDate.
KJ/Rust conversion layer
Comprehensive conversion layer is provided for many KJ types through [convert.h](kj-rs/convert.h).
Async fn support
FFI layer fully supports async fn functions. The resulting bridge will:
- expose
kj::Promiseasimpl Futureto Rust code. - expose
Futureaskj::Promiseto C++ code.
The resulting bridge promises and futures can be driven only by KJ event loop. You can still drive Rust native futures by other rust event loops like tokio when no ffi promises are used.
Rust type aliases support
We have merged in upstream PR that enables rust type aliases, which are important for reusing common cxx definitions across crates.