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.gz
tar -xzf emsdk-portable.tar.gz
source emsdk_portable/emsdk_env.sh
emsdk update
emsdk install sdk-incoming-64bit
emsdk activate sdk-incoming-64bit
cd ~/src
git clone https://github.com/rust-lang/rust && cd rust
./configure --enable-rustbuild --target=asmjs-unknown-emscripten,wasm32-unknown-emscripten
python2 src/rust/src/bootstrap/bootstrap.py
echo 'fn main() { println!("Hello, Emscripten!"); }' > hello.rs
build/x86_64-unknown-linux-gnu/stage2/bin/rustc --target=asmjs-unknown-emscripten hello.rs
node 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.