Skip to content

Instantly share code, notes, and snippets.

Last active February 28, 2017 04:05
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?

Build Rust with Emscripten support

For more up2date information:

Emscripten is the LLVM-based project to compile stuff into JavaScript. Luckily, Rust already uses LLVM and just recently got an upgrade to the used version of LLVM. Now emscripten uses a fork of LLVM, which is on the way to use more or less the same base LLVM as Rust. See the next-merge branch.

Simple 13 step recipe to build Rust with Emscripten support

To get it working is still a bit of work, so here are instructions to build it from scratch:

  1. curl -O
  2. tar -xzf emsdk-portable.tar.gz
  3. source emsdk_portable/
  4. emsdk update
  5. emsdk install sdk-incoming-64bit
  6. emsdk activate sdk-incoming-64bit
  7. cd ~/src
  8. git clone && cd rust
  9. ./configure --enable-rustbuild --target=asmjs-unknown-emscripten,wasm32-unknown-emscripten
  10. python2 src/rust/src/bootstrap/
  11. echo 'fn main() { println!("Hello, Emscripten!"); }' >
  12. build/x86_64-unknown-linux-gnu/stage2/bin/rustc --target=asmjs-unknown-emscripten
  13. node hello.js

Rustup usage

If you are using rustup, you can link the newly compiled rustc for easy usage:

rustup toolchain link emscripten ~/src/rust/build/x86_64-unknown-linux-gnu/stage2
rustup default emscripten
Copy link

saghm commented Aug 9, 2016

Hey, I found this while googling something, and I wanted to try it out! Unfortunately, I'm running into issues during step 17 (running the bootstrap script); it seems to be having trouble finding the commit of the llvm submodule to check out. I'm wondering if the error has something to do with missing arguments to ./configure? Nothing from the emsdk section of the instructions (1-13) seems to be used afterwards. I tried doing ./configure --enable-rustbuild --target=asmjs-unknown-emscripten --llvm-root=$DIR_CONTAINING_EMSDK/emsdk_portable/clang/fastcomp/build_incoming_64 --disable-llvm-version-check, but that doesn't work either, as the code in src/rustllvm fails immediately when looking for header files in the fastcomp directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment