This project provides C++ standard library and LibC support for the wasm32-unknown-unknown target, enabling C++/Rust interop through bindgen and cxx.
# Create build directory and compile
cmake -GNinja -S. -Bbuild -DCMAKE_INSTALL_PREFIX=`pwd`/install
cmake --build build
cmake --install buildThis will build and install:
- libc++ (C++ standard library)
- compiler-rt
- libc (OpenBSD-based)
- Required headers
The example project shows how to use this toolchain with Rust (with iced, bindgen, cxx and autocxx).
- Build the toolchain:
# Create build directory and compile
cmake -GNinja -S. -Bbuild -DCMAKE_INSTALL_PREFIX=`pwd`/install
cmake --build build
cmake --install build- Source the environment before building the rust project:
source install/env.sh- Build the Wasm project:
cd example
rustup override set nightly
wasm-pack build --target web- Start a local server to test:
python3 -m http.server 8080 --directory .- Requires nightly Rust compiler for
wasm_c_abi=specfeature (see rust-lang/rust#291) - C++ exceptions are disabled by default
- Based on OpenBSD libc implementation, but only a subset of the library is actually compiled, so beware of linking errors!
- Manual implementation of some libc functions is required (for example malloc/free)
- I created this project mainly for running CADara on webbrowsers. So for a more complex example compiling OpenCASCADE to
wasm32-unknown-unknown, see that.
This project builds upon: