open-standards/wai/wai-det-jpegai/build.sh
Transaction Science c2e52d1e16
Some checks failed
wai-det-jpegai WAISM float-level module of record / does this change touch it (push) Successful in 25s
repository checks / lockfiles, advisories, tests in CI, workflow hygiene, spec and section references, public text (push) Has been cancelled
WAI breaking changes and the conformance runner / WAI breaking · does this change touch WAI (push) Successful in 8s
WAI breaking changes and the conformance runner / WAI breaking · wire, record and API against main · linux (push) Successful in 50s
WAI breaking changes and the conformance runner / WAI breaking and conform · their tests, and the independent verifiers through wai conform · linux (push) Successful in 7m10s
wai-det-jpegai WAISM float-level module of record / linux · both checkers, F1, F2 on wasmtime (Cranelift, Winch, Pulley) and Wasmi, the planted faults (push) Successful in 13m54s
wai-det-jpegai WAISM float-level module of record / linux-arm64 · both checkers, F1, F2 on wasmtime (Cranelift, Winch, Pulley) and Wasmi, the planted faults (push) Failing after 14m33s
wai-det-jpegai: the JPEG AI exact decoder as the float level's module of record, with F1 and F2 on two instruction sets
One WebAssembly module with the interface of waism §5 and nothing else, decoding
wai.image.jpegai through wai-rs's exact decoder, the integer weight bundle arriving as the set
(the file sequence of norm.json and weights/*.json). Refusals are the capability's codes; a
codestream outside the decoder's configuration traps. Both checkers hold it at the float level
and refuse it R3 at the integer level. record/ keeps the module of record, built on Linux
x86_64 over main at 373fe3594 and named by its SHA-256 (53d54e58…, 666,425 bytes).

corpus.json, written by corpus.py from committed files: the reference codestream over the
pinned jpegai/v1 bundle, to the native exact decoder's pinned RGB8 (dbc494a5…), and three
refusal fixtures. host/ runs the probe on each engine first, in the same process (§6 check 10),
then every case on an instance of its own: wasmtime 50.0.1 with Cranelift, Winch and Pulley,
each with its NaN canonicalisation on and off, and Wasmi 2.0.0 built with `deterministic`.

What ran (rb, slot limiter):
- Linux x86_64 (Framework): F1 holds, the probe's bytes on the four engines with the NaN rule
  set and other bytes on the three without it; the planted probe fails F1. F2: the module of
  record gives every case the corpus's on all four engines, one run digest c7025bbc….
- Linux arm64 (Thor): build.sh with both checkers; F1 holds and the planted probe fails it; F2
  on the module of record and on this host's own build (ffb2c94f…, other bytes): eight runs,
  the same run digest. module-check.sh in full passes.
- The planted decoder (feature planted-nan-branch) gives the pinned RGB8 on the four engines
  the probe holds, another output on the three with the rule unset run past the probe, and the
  probe refuses those engines first (module_probe_mismatch), on both hosts.
- wai registry export --check, wai ops export --check and wai breaking against main: clean.

module-check.sh holds record/ to its manifest and both verdicts; wai-det-jpegai.yml runs the
build, F1, F2 and the planted faults on linux and linux-arm64.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-09 18:37:15 -05:00

85 lines
3.9 KiB
Shell

#!/usr/bin/env bash
# The JPEG AI exact decoder module, built and checked: the module of record of WAISM's float
# level.
#
# bash wai/wai-det-jpegai/build.sh [--out DIR] [--planted]
#
# Builds the crate for wasm32-unknown-unknown, scalar, and holds it to the profile with both of
# its checkers (../wai-module-check): the Rust checker and check-module.mjs must each give
# `held` at the float level and `refused R3` at the integer level, the same verdict at each.
# Then it writes it to DIR (default: the target directory's `module/`) as wai_det_jpegai.wasm
# and prints its size and SHA-256. With --planted it also builds the planted fault (the
# feature `planted-nan-branch`, README *The planted faults*), held to the same verdicts, as
# wai_det_jpegai.planted.wasm.
#
# The module names no path of this machine: the checkout, the Cargo home and the toolchain are
# remapped to /open-standards, /cargo and /rustup. Its bytes still depend on where and on what
# it is built (../wai-int-module/build.sh says why), so record/ is named by its SHA-256
# (record/manifest.json), and a build of this source on another host is held to the corpus,
# not to record/'s bytes.
#
# Needs bash, cargo with the wasm32-unknown-unknown target of the pinned toolchain, python3
# and node >= 18.
set -euo pipefail
CRATE="$(cd "$(dirname "$0")" && pwd -P)"
WAI="$(cd "$CRATE/.." && pwd -P)"
ROOT="$(cd "$WAI/.." && pwd -P)"
OUT=
PLANTED=0
while [ $# -gt 0 ]; do
case "$1" in
--out) OUT="$2"; shift 2 ;;
--planted) PLANTED=1; shift ;;
*) echo "usage: bash build.sh [--out DIR] [--planted]" >&2; exit 2 ;;
esac
done
for t in cargo rustc node python3; do
command -v "$t" >/dev/null || { echo "wai-det-jpegai: needs $t" >&2; exit 1; }
done
cd "$CRATE"
TARGET_BASE="${CARGO_TARGET_DIR:-$CRATE/target}"
OUT="${OUT:-$TARGET_BASE/module}"
mkdir -p "$OUT"
CARGO_HOME_DIR="$(cd "${CARGO_HOME:-$HOME/.cargo}" && pwd -P)"
RUSTUP_HOME_DIR="$(cd "${RUSTUP_HOME:-$HOME/.rustup}" && pwd -P)"
REMAP="--remap-path-prefix=$ROOT=/open-standards --remap-path-prefix=$CARGO_HOME_DIR=/cargo --remap-path-prefix=$RUSTUP_HOME_DIR=/rustup"
# The checker, built once.
cargo build --locked --release -q --manifest-path "$WAI/wai-module-check/Cargo.toml" --target-dir "$TARGET_BASE/checker"
CHECK="$TARGET_BASE/checker/release/wai-module-check"
variants=record
[ "$PLANTED" = 1 ] && variants="record planted"
for variant in $variants; do
name=wai_det_jpegai.wasm
features=()
if [ "$variant" = planted ]; then
name=wai_det_jpegai.planted.wasm
features=(--features planted-nan-branch)
fi
RUSTFLAGS="$REMAP" cargo build --locked --release --target wasm32-unknown-unknown --target-dir "$TARGET_BASE/$variant" ${features[@]+"${features[@]}"}
built="$TARGET_BASE/$variant/wasm32-unknown-unknown/release/wai_det_jpegai.wasm"
[ -f "$built" ] || { echo "wai-det-jpegai: the build left no $built" >&2; exit 1; }
rm -f "$OUT/$name"
# Both checkers, at both levels: held at the float level, refused R3 at the integer level,
# and the same verdict from each.
for level in float integer; do
rust=$("$CHECK" --level "$level" "$built" || true)
js=$(node "$WAI/wai-module-check/check-module.mjs" --level "$level" "$built" || true)
if [ "$rust" != "$js" ]; then
echo "wai-det-jpegai: $variant at the $level level: the Rust checker says '$rust', check-module.mjs '$js'" >&2
exit 1
fi
case "$level:$rust" in
float:held | integer:"refused R3 "*) ;;
*) echo "wai-det-jpegai: $variant at the $level level: $rust" >&2; exit 1 ;;
esac
echo "wai-det-jpegai: $variant at the $level level: $rust, from both checkers"
done
cp "$built" "$OUT/$name"
sum=$(python3 -I -c 'import hashlib,sys; print(hashlib.sha256(open(sys.argv[1],"rb").read()).hexdigest())' "$OUT/$name")
size=$(wc -c < "$OUT/$name" | tr -d ' ')
echo "wai-det-jpegai: $OUT/$name: $size bytes, SHA-256 $sum, held at the float level by both checkers"
done