Emscripten is a complete compiler toolchain to WebAssembly, using LLVM, with a special focus on speed, size, and the Web platform. Emscripten can be used to compile parts of IREE to WebAssembly for execution within web browsers or other Wasm runtimes.
IREE's runtime can be compiled through Emscripten in some limited configurations. More of the runtime will be supported over time.
IREE's compiler can be compiled through Emscripten with local changes. More work is needed for this to be generally supported.
Read https://emscripten.org/docs/getting_started/downloads.html and run
./emsdk install latest ./emsdk activate latest source ./emsdk_env.sh
Build and install at least the compiler tools on your host machine, or install them from a binary distribution:
$ cmake -G Ninja -B ../iree-build-host/ \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ \ -DCMAKE_INSTALL_PREFIX=../iree-build-host/install \ . $ cmake --build ../iree-build-host/ --target install
$ emcmake cmake -G Ninja -B ../iree-build-emscripten/ \ -DCMake_BUILD_TYPE=Release \ -DIREE_HOST_BINARY_ROOT=$(realpath ../iree-build-host/install) \ -DIREE_BUILD_TESTS=OFF \ -DIREE_BUILD_COMPILER=OFF \ .
Build:
cmake --build ../iree-build-emscripten/ \ --target iree_samples_simple_embedding_simple_embedding_vmvx_sync
Copy the outputs from the build process (e.g. simple_embedding_vmvx_sync.js
and simple_embedding_vmvx_sync.wasm
) into your application and follow instructions at either https://webassembly.org/getting-started/developers-guide/ or https://developer.mozilla.org/en-US/docs/WebAssembly/Loading_and_running.