#!/bin/sh # Build the cheap checks (crates/flow-checks, #96) as a WASI module and keep # it at .flow/checks.wasm, where the pipeline's WASM jobs run it from. # # scripts/checks-wasm.sh rebuild .flow/checks.wasm # scripts/checks-wasm.sh --check fail unless .flow/checks.wasm is what # the source builds (the fmt job runs this) # # The build is the same on any machine with the same toolchain (the build # image's, images/rust): the crate is std only, the workspace path is # remapped to /src and rust-src's to /rustc/COMMIT, and the module carries # no debug info. # Needs: rustup target wasm32-wasip1. set -eu cd "$(dirname "$0")/.." target=$(mktemp -d) trap 'rm -rf "$target"' EXIT # Where rust-src is installed, the standard library's panic locations name # it; map it to /rustc/COMMIT, as a toolchain without rust-src has them. src="$(rustc --print sysroot)/lib/rustlib/src/rust" commit=$(rustc -vV | sed -n 's/^commit-hash: //p') RUSTFLAGS="--remap-path-prefix=$(pwd)=/src --remap-path-prefix=$src=/rustc/$commit" \ CARGO_PROFILE_RELEASE_DEBUG=0 CARGO_PROFILE_RELEASE_STRIP=true CARGO_INCREMENTAL=0 \ cargo build -q --release --locked --target wasm32-wasip1 -p flow-checks --target-dir "$target" built="$target/wasm32-wasip1/release/flow-checks.wasm" if [ "${1:-}" = --check ]; then if cmp -s "$built" .flow/checks.wasm; then echo ".flow/checks.wasm is what crates/flow-checks builds ($(rustc --version))" else echo ".flow/checks.wasm differs from what crates/flow-checks builds: run scripts/checks-wasm.sh and commit it" >&2 exit 1 fi else cp "$built" .flow/checks.wasm echo "built .flow/checks.wasm ($(wc -c < .flow/checks.wasm) bytes, $(rustc --version))" fi