Cotton code
29 lines · 1.6 KB · ShellRaw
#!/usr/bin/env bash# pnpm rules:wasm — builds crates/cotton-rules into the Worker's rules module.## cotton-rules-wasm (wasm32, the `wasm` profile: size, LTO, abort on panic,# name section kept) → wasm-bindgen --target web → apps/business/src/rules/wasm/,# with stamp.json naming the sources it was built from. The module is CHECKED# IN (notes: the coordinator deploys from a Mac with no wasm toolchain, and the# Worker's vitest needs no cargo); scripts/__tests__/rules-wasm-stamp.test.ts# fails when crates/cotton-rules moves on and this was not run.## Needs: rustup target wasm32-unknown-unknown, and wasm-bindgen-cli at exactly# the crate's version (0.2.106) on PATH or in $WASM_BINDGEN.set -euo pipefailROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"OUT="$ROOT/apps/business/src/rules/wasm"TARGET_DIR="${CARGO_TARGET_DIR:-$ROOT/crates/target}"WANT="0.2.106"WB="${WASM_BINDGEN:-wasm-bindgen}"HAVE="$("$WB" --version | awk '{print $2}')"if [ "$HAVE" != "$WANT" ]; then  echo "rules:wasm: wasm-bindgen $WANT is needed, $WB is $HAVE (cargo install wasm-bindgen-cli --version $WANT --locked)" >&2  exit 1fi# From crates/, so rustup takes the pinned toolchain (crates/rust-toolchain.toml).(cd "$ROOT/crates" && cargo build -p cotton-rules-wasm --target wasm32-unknown-unknown --profile wasm)mkdir -p "$OUT""$WB" --target web --out-dir "$OUT" --out-name cotton_rules "$TARGET_DIR/wasm32-unknown-unknown/wasm/cotton_rules_wasm.wasm"(cd "$ROOT" && npx tsx scripts/rules/stamp.ts --write >/dev/null)echo "rules:wasm: $(wc -c < "$OUT/cotton_rules_bg.wasm") bytes raw, $(gzip -9c "$OUT/cotton_rules_bg.wasm" | wc -c) gzipped"