Files
faunosteo/scripts/wasm-build.sh
T
bchanot e58c7be362 fix(workspace): gate fixes after the security pass — warn-only advisories, drift gate sees new files, PATH guard appends, literal rm path, prctl arguments as unsigned long
check-all.sh gains a warn-only cargo deny check advisories stage (no nightly
job runs yet) and the ts-rs drift gate uses git status --porcelain so a new
untracked type file fails too (same in ci.yml); rust-env.sh appends an
absolute ~/.cargo/bin only; wasm-build.sh removes the literal
packages/core-wasm/pkg; the worker passes the unused prctl arguments as
c_ulong and its SAFETY comments no longer claim the kernel checks them.
2026-10-13 09:46:06 +02:00

35 lines
1.7 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
# `proofs`: the R0 trap exports; dropped when R2 builds the module the application ships.
cargo build -p faunosteo-wasm --release --target wasm32-unknown-unknown --locked --features proofs
out=packages/core-wasm/pkg
rm -rf packages/core-wasm/pkg
wasm-bindgen --target web --out-dir "$out" --out-name faunosteo_wasm \
target/wasm32-unknown-unknown/release/faunosteo_wasm.wasm
raw=$(wc -c < "$out/faunosteo_wasm_bg.wasm")
gz=$(gzip -9 -c "$out/faunosteo_wasm_bg.wasm" | wc -c)
echo "faunosteo_wasm_bg.wasm: ${raw} bytes raw, ${gz} bytes gzip -9"