Skip to content

Targeting WASM

Stanislav Vasilev edited this page Jun 27, 2024 · 8 revisions

The framework supports targeting WASM as a platform. This guide will help you set up everything to be able to easily deploy to WASM.

Installing Emscripten

To compile to WASM, you will need to install Emscripten, which is a toolchain for building C/C++ applications that can run on the web.

Linux and other Unixes

You need to manually install Emscripten, using the following commands:

user $ git clone https://github.com/emscripten-core/emsdk.git
user $ cd emsdk
user $ git pull
user $ ./emsdk install latest
user $ ./emsdk activate latest
user $ source ./emsdk_env.sh

Windows

On Windows, you need to have Python 3 installed. After that, run the following commands:

> git clone https://github.com/emscripten-core/emsdk.git
> cd emsdk
> git pull
> emsdk.bat install latest
> emsdk.bat activate latest
> emsdk_env.bat

macOS

On macOS, you can install Emscripten through homebrew:

user $ brew install emscripten

Test compilation

Once you have everything installed, run emcc --version to check if everything is set up correctly. If everything is fine, you can try compiling a project.

To compile a project, do the following:

  1. Create a new folder for building under the root project directory, for example: wasm-build
  2. Enter the folder
  3. Run emcmake cmake ..
  4. Compile using the provided generated build system. For example, with emmake: emmake make -j <number of compile jobs>
  5. Serve the compiled files: emrun <project name>.html
  6. Open the served URL in your browser

If built successfully, you should be presented with a page, similar to this:

Clone this wiki locally