#!/usr/bin/env bash # Build the compositor itself as a wasm component: build/compositor.wasm. # It imports the chandra:host interfaces (wit/host) and exports `run`; the host (wasmhost/, # build/wasmhost; or the Rust host-wasm/) provides the imports. Needs moon and wasm-tools. # scripts/build-compositor-wasm.sh set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)"; cd "$ROOT" export PATH="$ROOT/.tools/bin:$HOME/.moon/bin:$PATH" for t in moon wasm-tools; do command -v "$t" >/dev/null || { echo "error: $t not found" >&2; exit 1; } done moon build --target wasm --release components/compositor/gen 2>&1 | grep -E '^Error' -A8 || true [ "${PIPESTATUS[0]}" -eq 0 ] || { echo "error: moon build failed" >&2; exit 1; } core="_build/wasm/release/build/components/compositor/gen/gen.wasm" [ -f "$core" ] || { echo "error: $core missing" >&2; exit 1; } mkdir -p build wasm-tools component embed wit/host "$core" --world compositor --encoding utf16 -o build/compositor.embed.wasm wasm-tools component new build/compositor.embed.wasm -o build/compositor.wasm rm -f build/compositor.embed.wasm wasm-tools validate --features component-model build/compositor.wasm printf 'compositor.wasm %s bytes imports=[%s]\n' "$(stat -c %s build/compositor.wasm)" \ "$(wasm-tools component wit build/compositor.wasm | sed -n 's/^ import \(.*\);/\1/p' | paste -sd, -)"