Skip to content
Alon Zakai edited this page Mar 10, 2016 · 27 revisions

WebAssembly is a new binary format for executing code on the web. The overall plan is

  • Once browsers support WebAssembly, that will allow much faster start times (small download, much faster parsing) for Emscripten projects.
  • Emscripten will support compiling to WebAssembly with a compiler flag, so it'll be easy for projects to switch between WebAssembly and the current asm.js mode.
  • Binaryen is a new C++ library for WebAssembly that will help Emscripten in this area. It's being written as a separate project so others can use it too.

For more background, see

Building WebAssembly now

Setup

Things are still in progress, so the processing for building WebAssembly is not yet fully optimized. When things get more stable, we'll bundle Binaryen into Emscripten, etc., so things will be a lot easier. For now, here are the current steps:

  • Get Binaryen, and build it according to the instructions there.
  • Get emscripten's incoming branch.
  • Define BINARYEN_ROOT in your ~/.emscripten file to point to Binaryen (run emcc once if you never have, to generate that file).

If you want to run programs in a compiled WebAssembly interpreter, you can then do

emcc [..args..] -s BINARYEN=1

If you also want to run using the current WIP native WebAssembly support in browsers, you also need to

  • Get mozilla-inbound and build the JS engine under js/src. That provides a tool to build text to binary.
  • Make sure SPIDERMONKEY_ENGINE in ~/.emscripten points to the js shell that was built.

If you want to run programs in a compiled WebAssembly interpreter, you can then do

emcc [..args..] -s BINARYEN=1 -s 'BINARYEN_SCRIPTS="spidermonkify.py"'

New WebAssembly backend + Binaryen's s2wasm

The steps in the previous section all use Binaryen's asm2wasm tool to compile asm.js to WebAssembly. This option should fairly well, as it passes the passes the test suite. However, you should still expect issues here and there.

However, there is a new LLVM backend being developed for WebAssembly. It will eventually provide better results, but is not yet ready, see [New-WebAssembly-Backend](the new wasm backend web page).

Clone this wiki locally