diff --git a/.github/actions/prebuild-sp1-runner/action.yml b/.github/actions/prebuild-sp1-runner/action.yml new file mode 100644 index 00000000..71d0253a --- /dev/null +++ b/.github/actions/prebuild-sp1-runner/action.yml @@ -0,0 +1,37 @@ +name: Pre-build SP1 core runner binary +description: >- + Pre-build the sp1-core-executor-runner helper binary so the crate's build.rs + skips its nested cargo build. Returns the binary path as an output; set it as + SP1_CORE_RUNNER_OVERRIDE_BINARY on the steps that compile the crate. Requires + the repo checked out and a Rust toolchain on PATH. + +# `sp1-core-executor-runner`'s build.rs runs a nested `cargo build` and embeds +# the helper binary via `include_bytes!(env!("SP1_CORE_RUNNER_BINARY"))`. The +# binary lands under the registry source dir, which `Swatinem/rust-cache` does +# not preserve, while the build-script output that records its path is cached — +# so on a cache hit cargo skips the rebuild and `include_bytes!` fails with +# "couldn't read ...". The crate's build.rs honors `SP1_CORE_RUNNER_OVERRIDE_BINARY` +# (source-only, not in its docs): when set it skips the nested build and points +# at an external binary instead. Pin to the version resolved in Cargo.lock, not +# the `sp1-sdk` requirement (a caret that floats up to a later patch), so the +# prebuilt helper matches the linked runner crate. +# +# The path is returned as an output rather than written to $GITHUB_ENV so it is +# scoped to the steps that opt in (via env:), instead of every step in the job. +outputs: + override-binary: + description: >- + Absolute path to the prebuilt helper. Set it as + SP1_CORE_RUNNER_OVERRIDE_BINARY on steps that build sp1-core-executor-runner. + value: ${{ steps.prebuild.outputs.override-binary }} +runs: + using: composite + steps: + - id: prebuild + name: Pre-build SP1 core runner binary + shell: bash + run: | + VER="$(awk -F'"' '/^name = "sp1-core-executor-runner-binary"$/{f=1;next} f&&/^version = /{print $2;exit}' Cargo.lock)" + test -n "$VER" || { echo "could not determine sp1-core-executor-runner-binary version from Cargo.lock"; exit 1; } + cargo install sp1-core-executor-runner-binary --version "$VER" --root "$RUNNER_TEMP/sp1-core-runner" --force + echo "override-binary=$RUNNER_TEMP/sp1-core-runner/bin/sp1-core-executor-runner-binary" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5baf5252..c05d5018 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -37,10 +37,19 @@ jobs: - name: Install protoc uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3.0.0 + # `--all-features` pulls in `sp1-core-executor-runner`, whose build.rs + # embeds a nested-built helper that breaks clippy on a cache hit; the + # action pre-builds it and returns the path to use as the override (see the + # action for why). + - name: Pre-build SP1 core runner binary + id: sp1-runner + uses: ./.github/actions/prebuild-sp1-runner + - name: Run clippy run: cargo clippy --examples --tests --benches --all-features --all-targets --locked env: RUSTFLAGS: -D warnings + SP1_CORE_RUNNER_OVERRIDE_BINARY: ${{ steps.sp1-runner.outputs.override-binary }} fmt: name: Check code formatting diff --git a/.github/workflows/prover.yml b/.github/workflows/prover.yml index 1d540606..4760d282 100644 --- a/.github/workflows/prover.yml +++ b/.github/workflows/prover.yml @@ -52,17 +52,12 @@ jobs: - name: Install protoc uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3.0.0 - # `sp1-core-executor-runner`'s build.rs builds a helper binary and embeds - # it via `include_bytes!(env!("SP1_CORE_RUNNER_BINARY"))`. When pulled from - # crates.io, the binary is written *inside* the registry source dir - # (`~/.cargo/registry/src/.../sp1-core-executor-runner-X.Y.Z/target/`), - # which `Swatinem/rust-cache` does not preserve — but it does cache the - # build-script output that records the path. On a cache hit cargo skips - # rerunning the build script, then `include_bytes!` fails with "couldn't - # read ..." because the binary is gone. Clean these crates so build.rs - # always re-runs and re-creates the binary. - - name: Clean SP1 core executor runner crates - run: cargo clean -p sp1-core-executor-runner -p sp1-core-executor-runner-binary + # `sp1-core-executor-runner`'s build.rs embeds a nested-built helper that + # breaks on a cache hit; the action pre-builds it and returns the path to + # use as the override so build.rs skips the nested build (see the action). + - name: Pre-build SP1 core runner binary + id: sp1-runner + uses: ./.github/actions/prebuild-sp1-runner - name: Run prover-perf and post PR comment if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false @@ -70,6 +65,7 @@ jobs: ZKVM_MOCK: "1" ZKVM_PROFILING: "1" SKIP_VKEY_BUILD: "1" + SP1_CORE_RUNNER_OVERRIDE_BINARY: ${{ steps.sp1-runner.outputs.override-binary }} run: | cargo run --release -p strata-asm-prover-perf -- \ --post-to-gh \ @@ -85,5 +81,6 @@ jobs: ZKVM_MOCK: "1" ZKVM_PROFILING: "1" SKIP_VKEY_BUILD: "1" + SP1_CORE_RUNNER_OVERRIDE_BINARY: ${{ steps.sp1-runner.outputs.override-binary }} run: | cargo run --release -p strata-asm-prover-perf -- --programs asm-stf