Skip to content

Instantly share code, notes, and snippets.

@commiebstrd
Created November 26, 2017 18:53
Show Gist options
  • Save commiebstrd/a3035ba41eebc069a3e742229d58a246 to your computer and use it in GitHub Desktop.
Save commiebstrd/a3035ba41eebc069a3e742229d58a246 to your computer and use it in GitHub Desktop.
Targetting WASM from Rust on OSX

Rust stable (nightly) wasm on osx

Basic setup taken from The Path to Rust on the Web

  • Installing managed tools src src2
    • rustup target add wasm32-unknown-emscripten
    • brew install emscripten
    • brew install clang nodejs git - for llvm
  • Running cargo build --target=wasm32-unknown-emscripten claims to work but no wasm or js are created
    • emcc -v complains about system llvm not having wasm target
  • Install llvm-emscripten src
    CORES=4
    mkdir myfastcall
    cd myfastcall
    git clone https://github.com/kripken/emscripten-fastcomp
    cd emscripten-fastcomp
    git clone https://github.com/kripken/emscripten-fastcomp-clang tools/clang
    mkdir build
    cd build
    cmake .. -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86;X;JSBackend" -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DCLANG_INCLUDE_EXAMPLES=OFF -DCLANG_INCLUDE_TESTS=OFF
    make -j${CORES}
    perl -ipe "s/^LLVM_ROOT.*$/LLVM_ROOT = \\\"$(pwd)/bin\\\"" ~/.emscripten
    
  • Running cargo build --target=wasm32-unknown-emscripten now generates wasm and js files properly!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment