#!/usr/bin/env bash # The room client's files, as `wai dev` serves them, built into one directory: # # bash wai/quickstart/build-web.sh # # /room/ and /moq/ are joule-moq-web's page code (its tests left out), and # /pkg/ the three WebAssembly builds the pages load: joule_moq_web (MOQT and # receipts), joule_moq_web_e2ee (the same, and the member of an end-to-end encrypted room) # and wai_live_web (the room's records, layout and mixer), each through wasm-bindgen's web # target. The same files on every platform: an archive for any of them carries this # directory as share/wai/web/. # # Needs the wasm32-unknown-unknown target and the wasm-bindgen CLI at 0.2.127, the version # both crates pin. Run from anywhere; CARGO_TARGET_DIR is honoured. set -euo pipefail [ $# -eq 1 ] || { echo "usage: bash wai/quickstart/build-web.sh " >&2; exit 2; } ROOT=$(cd "$(dirname "$0")/../.." && pwd) OUT=$(mkdir -p "$1" && cd "$1" && pwd) JC="$ROOT/joule-code/joule-code-rs" WEB="$JC/crates/joule-moq-web/web" WLW="$ROOT/wai/wai-live-web" TARGET=${CARGO_TARGET_DIR:-$JC/target} export CARGO_TARGET_DIR="$TARGET" command -v wasm-bindgen >/dev/null || { echo "wasm-bindgen CLI 0.2.127 is needed (cargo install --locked wasm-bindgen-cli --version 0.2.127)" >&2; exit 2; } wasm-bindgen --version | grep -q ' 0\.2\.127$' || { echo "the wasm-bindgen CLI must be 0.2.127, the version both crates pin" >&2; exit 2; } rm -rf "$OUT/room" "$OUT/moq" "$OUT/pkg" mkdir -p "$OUT/room" "$OUT/moq" "$OUT/pkg" (cd "$JC" && cargo build --locked --release -p joule-moq-web --lib --target wasm32-unknown-unknown) wasm-bindgen --target web --out-dir "$OUT/pkg" --out-name joule_moq_web "$TARGET/wasm32-unknown-unknown/release/joule_moq_web.wasm" (cd "$JC" && cargo build --locked --profile wasm -p joule-moq-web --lib --target wasm32-unknown-unknown --features e2ee) wasm-bindgen --target web --remove-name-section --remove-producers-section --out-dir "$OUT/pkg" --out-name joule_moq_web_e2ee "$TARGET/wasm32-unknown-unknown/wasm/joule_moq_web.wasm" (cd "$WLW" && cargo build --locked --release --lib --target wasm32-unknown-unknown) wasm-bindgen --target web --out-dir "$OUT/pkg" --out-name wai_live_web "$TARGET/wasm32-unknown-unknown/release/wai_live_web.wasm" # The pages need the modules and the binaries alone, not the type declarations. rm -f "$OUT"/pkg/*.d.ts for d in room moq; do for f in "$WEB/$d"/*; do case "$f" in *.test.mjs) continue ;; esac cp "$f" "$OUT/$d/" done done ls -l "$OUT/pkg" echo "the room client is in $OUT"