Skip to content

Commit d662f5c

Browse files
committed
[puter] ci: only rebuild rewriter if rewriter src changes
1 parent 5240e96 commit d662f5c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ jobs:
5757
- name: Setup wasm-snip
5858
run: "cargo install --git https://github.com/r58playz/wasm-snip"
5959

60+
- name: Cache rewriter build artifacts
61+
uses: actions/cache@v4
62+
id: rewriter-cache
63+
with:
64+
path: |
65+
rewriter/wasm/out
66+
dist/scramjet.wasm.wasm
67+
key: rewriter-release-${{ hashFiles('rewriter/wasm/Cargo.toml', 'rewriter/wasm/src/**/*.rs', 'rewriter/wasm/build.sh') }}
68+
restore-keys: |
69+
rewriter-release-
70+
6071
- name: Pack Scramjet
6172
run: pnpm pack
6273

rewriter/wasm/build.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ else
2121
: "${FEATURES:=}"
2222
fi
2323

24+
# ----------------------------------------------------------------------------------
25+
# Build cache short‑circuit: if sources & build parameters unchanged, skip heavy work
26+
# We rely on CI (and local dev optional) to restore rewriter/wasm/out + dist/ wasm file.
27+
# Hash includes Rust source files, manifest, this script, and release/debug mode.
28+
# ----------------------------------------------------------------------------------
29+
MODE="release"
30+
if [ "${RELEASE:-0}" != "1" ]; then MODE="debug"; fi
31+
HASH_INPUT_FILES=(src/**/*.rs Cargo.toml build.sh)
32+
# shellcheck disable=SC2046
33+
SRC_HASH=$( (echo "MODE=${MODE}"; sha256sum $(git ls-files -z -- "src" | tr '\0' ' ' 2>/dev/null || find src -type f -name '*.rs'; echo Cargo.toml; echo build.sh) 2>/dev/null | sort -k2 | sha256sum ) | sha256sum | cut -d' ' -f1 ) || SRC_HASH="unknown"
34+
35+
if [ -f out/.build-hash ] && [ -f ../../dist/scramjet.wasm.wasm ] && [ "$SRC_HASH" != "unknown" ] && grep -q "$SRC_HASH" out/.build-hash; then
36+
echo "Rewriter sources unchanged (hash $SRC_HASH); skipping rebuild."
37+
exit 0
38+
fi
39+
2440
(
2541
export RUSTFLAGS='-Zlocation-detail=none -Zfmt-debug=none'
2642
if [ "${OPTIMIZE_FOR_SIZE:-0}" = "1" ]; then
@@ -112,4 +128,5 @@ fi
112128
mkdir -p dist/
113129

114130
cp rewriter/wasm/out/optimized.wasm dist/scramjet.wasm.wasm
131+
echo "$SRC_HASH" > rewriter/wasm/out/.build-hash || true
115132
echo "Rewriter Build Complete!"

0 commit comments

Comments
 (0)