#!/usr/bin/env bash # Build the WebAssembly target (openra3.html/.js/.wasm) with the Emscripten image. # # Browsers forbid synchronous on-demand file reads on the main thread, so assets # are preloaded into the module's filesystem. Prefer a compact, per-map set: one # map plus the tiles it uses: # # OPENRA3_WEB_ASSETS="$(mktemp -d)" \ # openra3 textures --map map_mp_2_feasel1 # copy these under the set's terrain/ # # then point OPENRA3_WEB_ASSETS at that directory. 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) if [ -n "${OPENRA3_WEB_ASSETS:-}" ]; then mounts+=(-v "$OPENRA3_WEB_ASSETS:/assets:ro") configure+=(-DOPENRA3_WEB_ASSETS=/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/openra3.html (+ .js/.wasm/.data)" echo "serve: python3 \"$ROOT/apps/web/serve.py\" --root \"$ROOT/$BUILD_DIR/bin\" --port 8199"