Files
desi_explorer/gui/scripts/build_web.sh
sam_oneal bd8a7da379
CI / Detect changed paths (pull_request) Failing after 1s
CI / Infra unit tests and vet (pull_request) Failing after 1s
CI / Odin unit tests and build (pull_request) Has been skipped
CI / API unit tests and lint (pull_request) Has been skipped
Move Odin renderer into gui/ with per-project Makefiles
Each sub-project (gui, api, infra) now owns its own Makefile, and the
root Makefile is a lean delegator for the base commands (run, build,
test, clean, fmt). Odin source, deps, and web assets live under gui/
(gui/src, gui/lib, gui/www), with scripts kept under gui/scripts for
build tooling only.
2026-08-31 13:45:58 -06:00

55 lines
1.8 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) at the repo root. Run via `make -C gui build-web`.
#
# 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 <repo>/build/web)
set -euo pipefail
# Resolve the gui/ project root so this script works regardless of CWD.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
GUI_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
ROOT_DIR="$(cd "${GUI_DIR}/.." && pwd)"
OUT_DIR="${OUT_DIR:-${ROOT_DIR}/build/web}"
ODIN_ROOT="${ODIN_ROOT:-$(odin root)}"
mkdir -p "${GUI_DIR}/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 "${GUI_DIR}/src" \
-target:js_wasm32 \
-build-mode:obj \
-define:RAYLIB_WASM_LIB=env.o \
-o:speed \
-collection:lib="${GUI_DIR}/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 "${GUI_DIR}/www/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}"