Here is a little toy project showing how to compile Rust code that can be called from C or JavaScript (via WebAssembly). To set this project up, I used
- Cargo
- cbindgen
- gcc
- make
- Node.js (8 or newer)
- Rust Nightly
- wasm-bindgen
- wasm-gc
- wasm-opt
Run make all
to build and run both the C and JavaScript test applications. You
should see each print
Hello, World! Bye!
You can build in release mode with make release
. This passes --release
to
Cargo, transforms the generated WebAssembly with wasm-gc
and wasm-opt
, and
minifies the generated JavaScript.