OXYGENHUB
◆ main oxygenflow / scripts / checks-wasm.sh
1.7 KiB · Bourne Again Shell (bash) · executable · last changed checks.wasm builds the same with or without rust-src: its standard-library paths map to /rustc/COMMIT, as the build image has them (refs #96) 8 days ago source blame history raw
1
#!/bin/sh
2
# Build the cheap checks (crates/flow-checks, #96) as a WASI module and keep
3
# it at .flow/checks.wasm, where the pipeline's WASM jobs run it from.
4
#
5
#   scripts/checks-wasm.sh          rebuild .flow/checks.wasm
6
#   scripts/checks-wasm.sh --check  fail unless .flow/checks.wasm is what
7
#                                   the source builds (the fmt job runs this)
8
#
9
# The build is the same on any machine with the same toolchain (the build
10
# image's, images/rust): the crate is std only, the workspace path is
11
# remapped to /src and rust-src's to /rustc/COMMIT, and the module carries
12
# no debug info.
13
# Needs: rustup target wasm32-wasip1.
14
set -eu
15
cd "$(dirname "$0")/.."
16
target=$(mktemp -d)
17
trap 'rm -rf "$target"' EXIT
18
# Where rust-src is installed, the standard library's panic locations name
19
# it; map it to /rustc/COMMIT, as a toolchain without rust-src has them.
20
src="$(rustc --print sysroot)/lib/rustlib/src/rust"
21
commit=$(rustc -vV | sed -n 's/^commit-hash: //p')
22
RUSTFLAGS="--remap-path-prefix=$(pwd)=/src --remap-path-prefix=$src=/rustc/$commit" \
23
CARGO_PROFILE_RELEASE_DEBUG=0 CARGO_PROFILE_RELEASE_STRIP=true CARGO_INCREMENTAL=0 \
24
    cargo build -q --release --locked --target wasm32-wasip1 -p flow-checks --target-dir "$target"
25
built="$target/wasm32-wasip1/release/flow-checks.wasm"
26
if [ "${1:-}" = --check ]; then
27
    if cmp -s "$built" .flow/checks.wasm; then
28
        echo ".flow/checks.wasm is what crates/flow-checks builds ($(rustc --version))"
29
    else
30
        echo ".flow/checks.wasm differs from what crates/flow-checks builds: run scripts/checks-wasm.sh and commit it" >&2
31
        exit 1
32
    fi
33
else
34
    cp "$built" .flow/checks.wasm
35
    echo "built .flow/checks.wasm ($(wc -c < .flow/checks.wasm) bytes, $(rustc --version))"
36
fi