Skip to content

maximmaxim345/wasm32-unknown-unknown-libcxx

Repository files navigation

wasm32-unknown-unknown-libcxx

This project provides C++ standard library and LibC support for the wasm32-unknown-unknown target, enabling C++/Rust interop through bindgen and cxx.

Building the Libraries

# Create build directory and compile
cmake -GNinja -S. -Bbuild -DCMAKE_INSTALL_PREFIX=`pwd`/install
cmake --build build
cmake --install build

This will build and install:

  • libc++ (C++ standard library)
  • compiler-rt
  • libc (OpenBSD-based)
  • Required headers

Using the Example Project

The example project shows how to use this toolchain with Rust (with iced, bindgen, cxx and autocxx).

Build Instructions

  1. Build the toolchain:
# Create build directory and compile
cmake -GNinja -S. -Bbuild -DCMAKE_INSTALL_PREFIX=`pwd`/install
cmake --build build
cmake --install build
  1. Source the environment before building the rust project:
source install/env.sh
  1. Build the Wasm project:
cd example
rustup override set nightly
wasm-pack build --target web
  1. Start a local server to test:
python3 -m http.server 8080 --directory .

Important Notes

  • Requires nightly Rust compiler for wasm_c_abi=spec feature (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.

Credits

This project builds upon:

About

LibC++ and LibC for wasm32-unknown-unknown enabling Rust-C++ interop in WebAssembly

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors