For more up2date information: http://www.hellorust.com/emscripten/
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.
To get it working is still a bit of work, so here are instructions to build it from scratch:
curl -O https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gztar -xzf emsdk-portable.tar.gzsource emsdk_portable/emsdk_env.shemsdk updateemsdk install sdk-incoming-64bitemsdk activate sdk-incoming-64bitcd ~/srcgit clone https://github.com/rust-lang/rust && cd rust./configure --enable-rustbuild --target=asmjs-unknown-emscripten,wasm32-unknown-emscriptenpython2 src/rust/src/bootstrap/bootstrap.pyecho 'fn main() { println!("Hello, Emscripten!"); }' > hello.rsbuild/x86_64-unknown-linux-gnu/stage2/bin/rustc --target=asmjs-unknown-emscripten hello.rsnode hello.js
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
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.