Rust
Rust binds the way a C++ header does: plain structs, impl blocks and pub fns become classes and functions, with no proc-macros and no hand-written glue. Write the file next to your other native sources and import it.
Setup
With the default Docker runner, builds for the web, Android, Linux and Windows need no Rust on your machine: cargo runs in the toolchain image, which carries the pinned Rust and the std of every target it builds. iOS and macOS builds run cargo on your Mac, as every build does under RUNNER=LOCAL, so those need a Rust toolchain - cargo plus the platform targets. cargo doubles as the incremental cache, so unchanged code rebuilds as a no-op.
The binding layer is a single dev dependency, and the Vite, Rollup, Webpack and React Native plugins already depend on it, so most projects get it transitively:
platform: 'wasi' skips Rust - there is no wasm32-wasip3 Rust target yet. And the wasm mt runtime links a std built with the atomics features: the toolchain image carries one, and under RUNNER=LOCAL crossbind downloads the same build when your rustc is the pinned one. With any other rustc it rebuilds std on nightly, which needs rustup toolchain install nightly --component rust-src once.Import a .rs file
Write Rust beside your C++ under src/native and import the file the way you import a header:
The bridge reads that one file's public items. Crates the file uses go into cargoDependencies in crossbind.config.js, the same map that lets you import a crate directly, with no Rust of your own - see crates.io:
What plain Rust maps to
| Rust | JavaScript |
|---|---|
struct + impl methods | class with methods (Type::new becomes the constructor) |
&str / &String parameters, String returns | strings |
i32 / f64 / bool | number / boolean |
i64 / u64 | BigInt, both directions |
Option<T> | null / undefined ↔ None |
Result<T, E> returns | throws an Error on Err |
impl Display | toString() |
free pub fn | plain exported function |
&OtherClass parameters | pass the other class's instance |
serde_json::Value | real JS values, deep-copied at the boundary |
Arc<Class> | shared ownership across several JS handles |
embind_rs::JsValue / JsFunction | live JS values by identity, and callbacks into JS |
Slices, collections, serde types and std::io streams have rows of their own in the full table. A function the bridge cannot carry is left out of the module - one with more than six parameters, or seven for new, for one.
st on the main thread, which in a browser means useWorker: false. Behind a worker, the browser default, functions cannot cross the boundary and identity does not survive structured cloning, so use serde_json::Value there.A panic inside a binding reaches JavaScript as an Error carrying the panic message. Treat it as a crash: on wasm the instance is spent afterwards, so start a fresh module rather than calling into it again. A wasm build that links Rust also gets a 1 MiB stack instead of Emscripten's 64 KiB; for more, set -sSTACK_SIZE in targetSpecs binary.emccFlags.
To ship Rust for other projects to install, publish the crate as a package: see Publishing packages.
TypeScript
Generated declarations live under .crossbind/, never in your source tree. A .rs import is typed by a declaration that mirrors its path under .crossbind/types/, which @crossbind/typescript-config overlays with rootDirs. Add the package as a dev dependency and extend it once (TypeScript 5.5 or later):
The same dts: 'promise' note from C++ applies here.