2.5 KiB
2.5 KiB
WASM Build Guide
This guide covers building the experimental WebAssembly version of YAZE.
Prerequisites
- Emscripten SDK (emsdk)
- Install from emscripten.org.
- Activate the environment:
source path/to/emsdk/emsdk_env.sh
- Ninja Build System
brew install ninja(macOS) orapt-get install ninja-build(Linux).
- Python 3 (for serving locally).
Quick Build
Use the helper script for a one-step build:
# Build Release version (default)
./scripts/build-wasm.sh
# Build Debug version (with assertions and source maps)
./scripts/build-wasm.sh debug
# Build with AI runtime enabled (experimental)
./scripts/build-wasm.sh ai
The script handles:
- CMake configuration using
emcmake. - Compilation with
ninja. - Packaging assets (
src/web->dist/). - Ensuring
coi-serviceworker.jsis placed correctly for SharedArrayBuffer support.
Serving Locally
You cannot open index.html directly from the file system due to CORS and SharedArrayBuffer security requirements. You must serve it with specific headers.
# Use the helper script (Python based)
./scripts/serve-wasm.sh [port]
Or manually:
cd build-wasm/dist
python3 -m http.server 8080
Note: The helper script sets the required Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy headers.
Architecture
- Entry Point:
src/main_wasm.cpp(orsrc/main.cppwith__EMSCRIPTEN__blocks). - Shell:
src/web/index.htmltemplate (populated by CMake/Emscripten). - Threading: Uses
SharedArrayBufferandpthreadpool. Requires HTTPS or localhost. - Filesystem: Uses Emscripten's
IDBFSmounted at/home/web_user. Data persists in IndexedDB.
Troubleshooting
"SharedArrayBuffer is not defined"
- Cause: Missing security headers.
- Fix: Ensure you are serving with
COOP: same-originandCOEP: require-corp. - Check: Is
coi-serviceworker.jsloading? It polyfills these headers for GitHub Pages (which doesn't support them natively yet).
"Out of Memory" / "Asyncify" Crashes
- The build uses
ASYNCIFYto support blocking calls (likeim_gui_loop). - If the stack overflows, check
ASYNCIFY_STACK_SIZEinCMakePresets.json. - Ensure infinite loops yield back to the browser event loop.
"ReferenceError: idb... is not defined"
- Cause: Missing JS library imports.
- Fix: Check
CMAKE_EXE_LINKER_FLAGSinCMakePresets.json. It should include-lidbfs.js.