So you are intrigued what is and want to try it? Since December 22 it’s possible to . If you don’t know anything about , I recommend you to , it’s awesome! However you don’t need to know how to write programs in Rust for this guide. WebAssembly compile Rust to WASM Rust language read about it I’ve been stuck many times before I ran WASM in VM. I’ve spent hours figuring out what’s wrong on each step and I want to help you save your time. So let’s start! First of all you should install Rust language on your computer. The best way to do it is to use a tool named rustup. You can install it as easy as curl -sSf | sh https://sh.rustup.rs Optionally variable (I recommend to do it if you are going to learn and use Rust). configure your [PATH](https://www.rust-lang.org/en-US/install.html) environment Install stable Rust and rustup target rustup install stablerustup default stablerustup target add wasm32-unknown-emscripten Installing new target is needed to your code to WASM from your platform. cross-compile Download a , then run command below: portable version of Emscripten SDK source .**/**emsdk_env.sh Now check emcc version emcc -v Probably you’ll get Emscripten SDK (aka emsdk) version 1.35.0 installed but you need 1.37.0 (or higher) to be able to compile to WASM. Unfortunately there are no precompiled binaries (at the moment of publishing this guide) so you should compile Emscriten SDK from sources. emsdk updateemsdk install sdk-incoming-64bitemsdk activate sdk-incoming-64bit It will take time (about 2 hours in my case) so be patient. When it’s done check again. It should tell you that you have (at least) 1.37.1 installed now. emcc -v From now you are all set up! Let’s try something! rustc --target=wasm32-unknown-emscripten hello.rs -o hello.html This will generate a bunch of files. We are only interested in three of them: hello.wasm hello.js hello.html First one is a binary. We can’t run wasm on it’s own. WebAssembly doesn’t have any I/O. So we need to wrap it into that will load, compile and run wasm. Generated HTML file provides an environment (with canvas and console) where we can run our code. WebAssembly JavaScript To run WebAssembly in browser you need either Chrome Canary Enabling WebAssembly in Chrome Canary or Firefox Nightly Enabling WebAssembly in Firefox Nightly Now run (or any other web server) and open (port may vary) in browser. You’ll see in Emscripten console. python -m SimpleHTTPServer http://localhost:8000/hello.html Hello, Emscripten! : Rust & WebAssembly hacker. Achievement unlocked Congrats! You just ran wasm in your browser! It looks like it’s not that hard to compile Rust to wasm, but believe me, a lot of people gave up doing this. Just follow comments from . There you can find my solutions to various issues. You unlikely will have any if you follow this guide step-by-step. Brendan Eich’s tweet Unfortunately Node.js doesn’t have full support of WebAssembly. However you can use or (I had no luck with it using rustc). polyfill [interpret-wasm](https://github.com/kripken/emscripten/wiki/WebAssembly#binaryen-methods) Binaryen method : you run wasm in Node.js! Clone , then switch to branch and from sources. Run script using built node with option. Update (Jan 6, 2017) can this repo vee-eight-lkgr build Node.js hello.js --expose-wasm WebAssembly running in Node.js Whoohoo! : compiling Rust to . This needs some work because I’ll need to connect rustc to emcc somehow and I don’t know how to do it yet. Ping me please if you can help! Next goal WebAssembly standalone Please let me know if you have any problems following this guide. I’ll try to help you and update guide to help other people too. Big thanks to ( ) for his help and hard work on Emscripten and Binaryen. Alon Zakai @kripken ( ) for reviewing this guide and always being awesome. Sean T. Larkin @TheLarkinn Ali Ijaz Sheikh ( ) for telling about branch of Node.js. @ofrobots vee-eight-lkgr About me: GitHub digger. TypeScript user. Rust newbie. Things-I-love evangelist. Public speaker (if you speak Russian you may like my or ). Contributed to React, Babel, etc. Helping maintain and . Part of crew, co-organizer of . Community guy whose glass is always half-full. public talk about WebAssembly other talks compat-table babel-preset-env MoscowJS BeerJS Moscow Follow me on Twitter @chicoxyzzy
Share Your Thoughts