WIT package, MoonBit components, Node host and tests (WIP)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e5548fc067
commit
e0bde1d150
125 files changed
+8681
No files matched your search
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
# Build every component: MoonBit -> core wasm -> component -> jco transpile.
|
||||
# scripts/build.sh [component-name ...] (default: all in components.txt)
|
||||
# Outputs: build/components/<n>.wasm (+ <n>.meta.json), build/jco/<n>/ (JS host glue).
|
||||
# Components build independently: rebuilding one never touches another's output.
|
||||
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 (run scripts/setup-toolchain.sh; install MoonBit)" >&2; exit 1; }
|
||||
done
|
||||
JCO="$ROOT/host/node_modules/.bin/jco"
|
||||
[ -x "$JCO" ] || { echo "error: jco missing; run: (cd host && npm ci)" >&2; exit 1; }
|
||||
|
||||
want=("$@")
|
||||
mkdir -p build/components build/jco
|
||||
wasm-tools component wit wit >/dev/null # the WIT package itself must parse
|
||||
|
||||
echo ">> moon build (wasm, release)"
|
||||
moon build --target wasm --release 2>&1 | grep -v -E 'Warning|^\s*$|[│╭╰─]' || true
|
||||
[ "${PIPESTATUS[0]}" -eq 0 ] || { echo "error: moon build failed" >&2; exit 1; }
|
||||
|
||||
while read -r name world; do
|
||||
case "$name" in ''|'#'*) continue;; esac
|
||||
if [ ${#want[@]} -gt 0 ] && [[ ! " ${want[*]} " =~ " $name " ]]; then continue; fi
|
||||
core="_build/wasm/release/build/components/$name/gen/gen.wasm"
|
||||
[ -f "$core" ] || { echo "error: $core missing" >&2; exit 1; }
|
||||
out="build/components/$name.wasm"
|
||||
wasm-tools component embed wit "$core" --world "$world" --encoding utf16 -o "build/components/$name.embed.wasm"
|
||||
wasm-tools component new "build/components/$name.embed.wasm" -o "$out"
|
||||
rm -f "build/components/$name.embed.wasm"
|
||||
wasm-tools validate --features component-model "$out"
|
||||
# Conformance: the component must be a valid implementation of its world.
|
||||
wasm-tools component targets --world "$world" wit "$out" >/dev/null
|
||||
# Capability manifest: which host interfaces the binary imports.
|
||||
imports="$(wasm-tools component wit "$out" | sed -n 's/^ import moonplasma:desktop\/\([a-z-]*\)@.*;/\1/p' | grep -v '^types$' | sort | paste -sd, - || true)"
|
||||
exports="$(wasm-tools component wit "$out" | sed -n 's/^ export moonplasma:desktop\/\([a-z-]*\)@.*;/\1/p' | sort | paste -sd, -)"
|
||||
printf '{"name":"%s","world":"%s","imports":[%s],"exports":[%s]}\n' "$name" "$world" \
|
||||
"$(echo "$imports" | sed 's/\([a-z-]\+\)/"\1"/g')" "$(echo "$exports" | sed 's/\([a-z-]\+\)/"\1"/g')" \
|
||||
> "build/components/$name.meta.json"
|
||||
rm -rf "build/jco/$name"
|
||||
"$JCO" transpile "$out" -o "build/jco/$name" --instantiation async --no-typescript --name "$name" >/dev/null
|
||||
echo "{\"type\":\"module\"}" > "build/jco/$name/package.json"
|
||||
printf ' %-14s %-16s %7s bytes imports=[%s]\n' "$name" "$world" "$(stat -c %s "$out")" "$imports"
|
||||
done < scripts/components.txt
|
||||
echo "ok"
|
||||
@@ -0,0 +1,5 @@
|
||||
# <component dir name> <WIT world>
|
||||
clock-digital clock-widget
|
||||
clock-binary clock-widget
|
||||
launcher launcher-widget
|
||||
shell shell
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/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
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
# Install wasm-tools, wit-bindgen and wasmtime (static release binaries) into
|
||||
# ./.tools/bin without root. jco is installed by `npm ci` in host/.
|
||||
# MoonBit itself is installed separately (https://www.moonbitlang.com/download).
|
||||
set -euo pipefail
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
# shellcheck source=versions.env
|
||||
source "$ROOT/scripts/versions.env"
|
||||
BIN="$ROOT/.tools/bin"
|
||||
mkdir -p "$BIN"
|
||||
tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
|
||||
|
||||
have() { [ -x "$BIN/$1" ] && "$BIN/$1" --version 2>/dev/null | grep -q "$2"; }
|
||||
|
||||
arch="$(uname -m)"
|
||||
[ "$arch" = "x86_64" ] || { echo "error: only x86_64 linux is wired up in setup-toolchain.sh (got $arch)" >&2; exit 1; }
|
||||
|
||||
if ! have wasm-tools "$WASM_TOOLS_VERSION"; then
|
||||
echo ">> wasm-tools $WASM_TOOLS_VERSION"
|
||||
curl -fsSL "https://github.com/bytecodealliance/wasm-tools/releases/download/v$WASM_TOOLS_VERSION/wasm-tools-$WASM_TOOLS_VERSION-x86_64-linux.tar.gz" | tar xz -C "$tmp"
|
||||
cp "$tmp"/wasm-tools-*/wasm-tools "$BIN/"
|
||||
fi
|
||||
if ! have wit-bindgen "$WIT_BINDGEN_VERSION"; then
|
||||
echo ">> wit-bindgen $WIT_BINDGEN_VERSION"
|
||||
curl -fsSL "https://github.com/bytecodealliance/wit-bindgen/releases/download/v$WIT_BINDGEN_VERSION/wit-bindgen-$WIT_BINDGEN_VERSION-x86_64-linux.tar.gz" | tar xz -C "$tmp"
|
||||
cp "$tmp"/wit-bindgen-*/wit-bindgen "$BIN/"
|
||||
fi
|
||||
if ! have wasmtime "$WASMTIME_VERSION"; then
|
||||
echo ">> wasmtime $WASMTIME_VERSION"
|
||||
curl -fsSL "https://github.com/bytecodealliance/wasmtime/releases/download/v$WASMTIME_VERSION/wasmtime-v$WASMTIME_VERSION-x86_64-linux.tar.xz" | tar xJ -C "$tmp"
|
||||
cp "$tmp"/wasmtime-*/wasmtime "$BIN/"
|
||||
fi
|
||||
echo "installed into $BIN:"
|
||||
"$BIN/wasm-tools" --version; "$BIN/wit-bindgen" --version; "$BIN/wasmtime" --version
|
||||
@@ -0,0 +1,5 @@
|
||||
# Pinned toolchain versions (see docs/TOOLCHAIN.md).
|
||||
WASM_TOOLS_VERSION=1.263.0
|
||||
WIT_BINDGEN_VERSION=0.63.0
|
||||
WASMTIME_VERSION=51.0.0
|
||||
JCO_VERSION=1.42.0
|
||||
Reference in new issue
Block a user