Files
endless-runner-vibe/build_web.sh
Gabriel Kaszewski 951bd51f12 Add WebAssembly build support via Emscripten
- Cargo.toml: gate `wayland` feature behind cfg(not(wasm32)) so the
  dependency resolves correctly for both native and web targets
- .cargo/config.toml: WASM linker flags (ASYNCIFY, GLFW, memory growth)
- build_web.sh: sets required EMCC_CFLAGS, builds, copies artefacts to web/;
  accepts --serve to start a local HTTP server
- web/index.html: minimal Emscripten shell with canvas and status line
- .gitignore: exclude generated web/*.js and web/*.wasm artefacts
- README: document web build prerequisites and usage

ASYNCIFY lets the native while-loop main loop run unchanged in the browser.
Build output: ~267 KB JS + ~458 KB WASM.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 00:35:21 +01:00

25 lines
730 B
Bash
Executable File

#!/usr/bin/env bash
# Build the endless runner for WebAssembly via Emscripten.
# Usage: ./build_web.sh [--serve]
set -euo pipefail
# Flags required by raylib-sys for WASM compilation.
export EMCC_CFLAGS="-O3 -sUSE_GLFW=3 -sASSERTIONS=1 -sWASM=1 -sASYNCIFY -sGL_ENABLE_GET_PROC_ADDRESS=1"
echo "Building for wasm32-unknown-emscripten..."
cargo build --target wasm32-unknown-emscripten --release
OUT=target/wasm32-unknown-emscripten/release
echo "Copying build artefacts to web/..."
cp "$OUT/endless_runner.js" web/
cp "$OUT/endless_runner.wasm" web/
echo ""
echo "Build complete. Output in web/"
if [[ "${1-}" == "--serve" ]]; then
echo "Serving at http://localhost:8080"
python3 -m http.server 8080 --directory web
fi