12# Build the Box3D physics module (M10): fetches the pinned box3d commit,3# builds libbox3d.a for wasm32 (emcmake), and links the game shim into4# static/dist/box3d.mjs + .wasm. Requires emscripten (brew install5# emscripten) and cmake. See tools/physics-spike/README.md for the spike6# that validated this path.7set -euo pipefail89BOX3D_COMMIT=3fc20f5b453ba9e14cdf54ecafa87a2a4bcdf53c10ROOT="$(cd "$(dirname "$0")/.." && pwd)"11EXTERN="$ROOT/extern/box3d"1213if [ ! -d "$EXTERN" ]; then14 mkdir -p "$ROOT/extern"15 git clone https://github.com/erincatto/box3d.git "$EXTERN"16fi17git -C "$EXTERN" fetch --depth 1 origin "$BOX3D_COMMIT" 2>/dev/null || true18git -C "$EXTERN" checkout -q "$BOX3D_COMMIT"1920emcmake cmake --fresh -S "$EXTERN" -B "$EXTERN/build-wasm" \21 -DCMAKE_BUILD_TYPE=Release \22 -DBOX3D_SAMPLES=OFF -DBOX3D_UNIT_TESTS=OFF -DBOX3D_BENCHMARKS=OFF \23 >/dev/null24cmake --build "$EXTERN/build-wasm" -j 8 >/dev/null2526mkdir -p "$ROOT/static/dist"27emcc "$ROOT/src/client/physics/shim.c" \28 "$EXTERN/build-wasm/src/libbox3d.a" \29 -I "$EXTERN/include" \30 -O2 \31 -sMODULARIZE=1 -sEXPORT_ES6=1 -sENVIRONMENT=web,node \32 -sALLOW_MEMORY_GROWTH=1 \33 -sEXPORTED_FUNCTIONS=_ph_init,_ph_dispose,_ph_begin_static,_ph_add_box,_ph_add_box_q,_ph_add_slab,_ph_add_mesh,_ph_add_bumper,_ph_add_bumper_q,_ph_end_static,_ph_remove_static,_ph_spawn_marble,_ph_destroy_marble,_ph_marble_ghost,_ph_marble_segment,_ph_marble_force,_ph_marble_jump,_ph_marble_mass,_ph_marble_restitution,_ph_gravity,_ph_step,_ph_marble_state,_ph_states,_ph_hits,_malloc,_free \34 -sEXPORTED_RUNTIME_METHODS=HEAPF64,HEAPF32,HEAP32 \35 -o "$ROOT/static/dist/box3d.mjs"3637echo "built static/dist/box3d.mjs ($(du -h "$ROOT/static/dist/box3d.wasm" | cut -f1))"