Files
desi_explorer/scripts/build_web.sh
T
2026-08-30 20:45:54 -06:00

49 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Builds the WebAssembly ("web") build of DESI Explorer with Odin
# (js_wasm32) + emscripten. Output: build/web/index.html (+ index.wasm, odin.js).
#
# Requires:
# - `odin` on PATH with the js_wasm32 target
# - emcc / emscripten active in PATH
# Optional:
# - ODIN_ROOT (defaults to `odin root`)
# - OUT_DIR (defaults to build/web)
set -euo pipefail
OUT_DIR="${OUT_DIR:-build/web}"
ODIN_ROOT="${ODIN_ROOT:-$(odin root)}"
mkdir -p lib/local
mkdir -p "$OUT_DIR"
# The Odin compiler emits a wasm object; raylib's C code is linked later by
# emcc. `-define:RAYLIB_WASM_LIB=env.o` stops the compiler from trying to
# link the raylib lib itself (emcc does that; it ends up in the final module).
odin build src \
-target:js_wasm32 \
-build-mode:obj \
-define:RAYLIB_WASM_LIB=env.o \
-o:speed \
-collection:lib=lib/local \
-out:"${OUT_DIR}/game"
# Odin's JS runtime glue; the generated module imports functions from it.
cp "${ODIN_ROOT}/core/sys/wasm/js/odin.js" "${OUT_DIR}/odin.js"
# Link with emscripten against raylib's prebuilt web library. Flags mirror the
# known-good karl-zylinski/odin-raylib-web template.
emcc \
-o "${OUT_DIR}/index.html" \
"${OUT_DIR}/game.obj" \
"${ODIN_ROOT}/vendor/raylib/wasm/libraylib.web.a" \
--shell-file scripts/web/index_template.html \
-sEXPORTED_RUNTIME_METHODS="['HEAPF32']" \
-sUSE_GLFW=3 \
-sWASM_BIGINT \
-sWARN_ON_UNDEFINED_SYMBOLS=0 \
-sASSERTIONS
rm -f "${OUT_DIR}/game.obj"
echo "Web build created in ${OUT_DIR}"