#!/usr/bin/env bash # Build the WebAssembly target (openra3.js/.wasm + worker + page) with the # Emscripten image. # # The engine runs inside a plain Web Worker and renders into an OffscreenCanvas # with no SDL, so assets load on demand: point OPENRA3_WEB_ASSETS at the # extracted asset tree and the build generates an assets manifest, embeds it, and # registers every file as an Emscripten lazy file at startup. The browser then # fetches each asset only when the engine opens it. # # OPENRA3_WEB_ASSETS=/path/to/assets scripts/build-wasm.sh # # open http://localhost:8199/index.html set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" IMAGE="${OPENRA3_WASM_IMAGE:-openra3-wasm:local}" BUILD_DIR="${1:-build/wasm}" docker build --target dev -f "$ROOT/Dockerfile.wasm" -t "$IMAGE" "$ROOT" mounts=(-v "$ROOT:/work") configure=(-DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/emscripten-wasm.cmake -DCMAKE_BUILD_TYPE=Release) serve_assets=() if [ -n "${OPENRA3_WEB_ASSETS:-}" ]; then mounts+=(-v "$OPENRA3_WEB_ASSETS:/assets:ro") manifest="$ROOT/$BUILD_DIR/assets.manifest.json" mkdir -p "$(dirname "$manifest")" python3 "$ROOT/scripts/make_web_manifest.py" --root "$OPENRA3_WEB_ASSETS" --out "$manifest" configure+=(-DOPENRA3_WEB_MANIFEST="/work/$BUILD_DIR/assets.manifest.json") serve_assets=(--assets "$OPENRA3_WEB_ASSETS") fi docker run --rm "${mounts[@]}" -w /work "$IMAGE" cmake -S . -B "$BUILD_DIR" -G Ninja "${configure[@]}" docker run --rm "${mounts[@]}" -w /work "$IMAGE" cmake --build "$BUILD_DIR" -j echo "WebAssembly: $ROOT/$BUILD_DIR/bin/index.html (+ openra3.js/.wasm, openra3.worker.js)" echo "serve: python3 \"$ROOT/apps/web/serve.py\" --root \"$ROOT/$BUILD_DIR/bin\" ${serve_assets[*]:-}"