Files
chandra/scripts/gen-bindings.sh
T
2026-11-24 23:36:35 +00:00

25 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# (Re)generate the MoonBit guest bindings for every component from wit/.
#
# Shared import bindings land in ./interface and ./world (one copy for all
# components); each component's export bindings land in components/<n>/gen.
# The first run also writes moon.pkg for each package; later runs pass
# --ignore-stub so hand-edited moon.pkg / stub.mbt files are preserved.
# `scripts/gen-bindings.sh --check` fails if regeneration changes tracked files.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"; cd "$ROOT"
export PATH="$ROOT/.tools/bin:$PATH"
while read -r name world; do
case "$name" in ''|'#'*) continue;; esac
extra=()
[ -d "components/$name/gen" ] && extra+=(--ignore-stub)
wit-bindgen moonbit wit --world "$world" --out-dir . \
--gen-dir "components/$name/gen" --project-name moonplasma/desktop \
--ignore-module-file "${extra[@]}" >/dev/null 2>"$ROOT/.tools/bindgen.log" || { cat "$ROOT/.tools/bindgen.log" >&2; exit 1; }
echo "bindings: $name ($world)"
done < scripts/components.txt
if [ "${1:-}" = "--check" ]; then
git diff --exit-code -- interface world components '*/gen/*' \
|| { echo "error: generated bindings are stale; run scripts/gen-bindings.sh and commit" >&2; exit 1; }
fi