packages/core-wasm: browser-safe CoreRuntime (synchronous calls once ready; a WebAssembly.RuntimeError poisons the instance, the call answers internal, a fresh instance comes from the kept compiled module and a glue record imported in advance; at most 3 recoveries per page; retry after a load failure), SheetSession (handle rebuilt per instance generation, never called on a dropped one; invalid_sheet without poisoning), Node source. crates/wasm: SheetHandle (sheet held in the module memory). Two builds: pkg/ shipped without trap exports (checked), pkg-proofs/ for the trap tests; BUILD_STAMP (hash of the Rust sources) refused when missing or stale by the vitest global setup instead of skipping. Failure envelope carries a numeric found version; compact JS-number output.
50 lines
2.3 KiB
Bash
Executable File
50 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Builds the browser module of crates/wasm into packages/core-wasm/pkg (git-ignored).
|
|
# `pnpm wasm:build` runs it on the native toolchain (wasm32-unknown-unknown target and the
|
|
# wasm-bindgen CLI installed by rustup / cargo install, docs/development/RUST.md §1);
|
|
# `pnpm wasm:build:docker` runs the same file inside the reference builder image.
|
|
# The wasm-bindgen CLI must be the exact version of the wasm-bindgen crate in Cargo.lock
|
|
# (wasm-bindgen >= 0.2.128 refuses a mismatch at runtime; we refuse it up front).
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "$0")/.."
|
|
. scripts/rust-env.sh
|
|
|
|
lock_version="$(awk '/^name = "wasm-bindgen"$/ { getline; sub(/^version = "/, ""); sub(/"$/, ""); print; exit }' Cargo.lock)"
|
|
if ! command -v wasm-bindgen >/dev/null 2>&1; then
|
|
echo "wasm-bindgen CLI not found on PATH: cargo install wasm-bindgen-cli --version ${lock_version} --locked" >&2
|
|
exit 1
|
|
fi
|
|
cli_version="$(wasm-bindgen --version | awk '{ print $2 }')"
|
|
if [ "$lock_version" != "$cli_version" ]; then
|
|
echo "wasm-bindgen crate ${lock_version} (Cargo.lock) != wasm-bindgen-cli ${cli_version} on PATH: cargo install wasm-bindgen-cli --version ${lock_version} --locked" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Two modules from the same sources: pkg/ is the one the application ships (no trap export),
|
|
# pkg-proofs/ adds the R0 trap exports for the poison-and-reinstantiate tests only (R2 plan P10).
|
|
build_module() {
|
|
local out="$1"
|
|
shift
|
|
cargo build -p faunosteo-wasm --release --target wasm32-unknown-unknown --locked "$@"
|
|
rm -rf "$out"
|
|
wasm-bindgen --target web --out-dir "$out" --out-name faunosteo_wasm \
|
|
target/wasm32-unknown-unknown/release/faunosteo_wasm.wasm
|
|
}
|
|
|
|
stamp="$(node scripts/wasm-stamp.mjs)"
|
|
build_module packages/core-wasm/pkg-proofs --features proofs
|
|
echo "$stamp" > packages/core-wasm/pkg-proofs/BUILD_STAMP
|
|
build_module packages/core-wasm/pkg
|
|
echo "$stamp" > packages/core-wasm/pkg/BUILD_STAMP
|
|
|
|
# The shipped module must not carry a proof export.
|
|
if grep -Eq 'panic_for_test|recurse_for_test' packages/core-wasm/pkg/faunosteo_wasm.d.ts; then
|
|
echo "packages/core-wasm/pkg exports a proof function: refusing to ship it" >&2
|
|
exit 1
|
|
fi
|
|
|
|
raw=$(wc -c < packages/core-wasm/pkg/faunosteo_wasm_bg.wasm)
|
|
gz=$(gzip -9 -c packages/core-wasm/pkg/faunosteo_wasm_bg.wasm | wc -c)
|
|
echo "faunosteo_wasm_bg.wasm (shipped): ${raw} bytes raw, ${gz} bytes gzip -9"
|