Compiling for the Web


To compile export templates for the Web, the following is required:

Building export templates

Start a terminal and set the environment variable EMSCRIPTEN_ROOT to the installation directory of Emscripten:

If you installed Emscripten via the Emscripten SDK, declare the variable with a path to the downloaded folder:

export EMSCRIPTEN_ROOT=~/emsdk/emscripten/master

If you installed Emscripten via package manager, the path can be retrieved with the em-config command:


On Windows you can set the environment variable in the system settings or in the command prompt:

set EMSCRIPTEN_ROOT="C:\emsdk\emscripten\master"

Now go to the root directory of the engine source code and instruct SCons to build the JavaScript platform. Specify target as either release for a release build or release_debug for a debug build:

scons platform=javascript tools=no target=release
scons platform=javascript tools=no target=release_debug

The engine will now be compiled to WebAssembly by Emscripten. If all goes well, the resulting file will be placed in the bin subdirectory. Its name is for release or for debug.

Finally, rename the zip archive to for the release template:

mv bin/ bin/

And for the debug template:

mv bin/ bin/

Building per asm.js translation or LLVM backend

WebAssembly can be compiled in two ways: The default is to first compile to asm.js, a highly optimizable subset of JavaScript, using Emscripten’s fastcomp fork of LLVM. This code is then translated to WebAssembly using a tool called asm2wasm. Emscripten automatically takes care of both processes, we simply run SCons.

The other method uses LLVM’s WebAssembly backend. This backend is not yet available in release versions of LLVM, only in development builds built with LLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly. Compiling with this backend outputs files in LLVM’s .s format, which is translated into actual WebAssembly using a tool called s2wasm. Emscripten manages these processes as well, so we just invoke SCons.

In order to choose one of the two methods, the LLVM_ROOT variable in the Emscripten configuration file ~/.emscripten is set. If it points to a directory containing binaries of Emscripten’s fastcomp fork of clang, asm2wasm is used. This is the default in a normal Emscripten installation. Otherwise, LLVM binaries built with the WebAssembly backend will be expected and s2wasm is used. On Windows, make sure to escape backslashes of paths within this file as double backslashes \\ or use Unix-style paths with a single forward slash /.