Files
solvecraft/.github/actions/cpp-reference/action.yml
T
bherbruck 99ffb23a2d ci: build without sccache when its cache storage is down
The Actions cache answered 503 ServerBusy when sccache started, and main's
difftest-sweep failed on it (run 40359891566). Start the server explicitly
and fall back to a cold build, with a warning, if it can't start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJzQKZ9sjU1DhgS253e8J5
2026-10-26 12:39:03 -04:00

85 lines
3.6 KiB
YAML

name: C++ reference
description: >
Clones upstream at the pinned commit, enables sccache and installs the C++ reference
(bin/cpp layout) into $SOLIDCORE_CPP_DIR, so the cpp feature of solidcore-ffi builds.
Expects UPSTREAM_REPO, UPSTREAM_COMMIT and SOLIDCORE_CPP_DIR in the job environment.
runs:
using: composite
steps:
- name: Clone upstream at pinned commit
shell: bash
run: |
git init upstream
git -C upstream remote add origin "$UPSTREAM_REPO"
git -C upstream fetch --depth 1 origin "$UPSTREAM_COMMIT" \
|| git -C upstream fetch origin
git -C upstream checkout --detach "$UPSTREAM_COMMIT"
# sccache caches the ~200 shim objects solidcore-ffi compiles (the cc crate wraps the
# C++ compiler in RUSTC_WRAPPER when it is sccache) and the workspace crates, which
# rust-cache does not keep; both survive across runs in the GitHub Actions cache.
- name: Set up sccache
uses: mozilla-actions/sccache-action@v0.0.11
- name: Enable sccache
shell: bash
run: |
echo "SCCACHE_GHA_ENABLED=true" >> "$GITHUB_ENV"
echo "RUSTC_WRAPPER=sccache" >> "$GITHUB_ENV"
# The difftest run is idle for sccache for minutes; without this the server
# exits after 10 idle minutes and the stats printed at the end read zero.
echo "SCCACHE_IDLE_TIMEOUT=0" >> "$GITHUB_ENV"
# Start the server now, so a cache-storage outage (the Actions cache answering
# 503 ServerBusy at startup) costs a cold build instead of failing the job.
if ! SCCACHE_GHA_ENABLED=true SCCACHE_IDLE_TIMEOUT=0 sccache --start-server; then
echo "::warning::sccache could not start (cache storage unavailable); building without it"
echo "RUSTC_WRAPPER=" >> "$GITHUB_ENV"
echo "SCCACHE_GHA_ENABLED=false" >> "$GITHUB_ENV"
fi
# The C++ reference (bin/cpp/lib) comes prebuilt from the GitHub Release that
# .github/workflows/cpp-reference.yml publishes for scripts/cpp-ref-key.sh's key.
# When none matches (a PR that changes harness/cpp before it is published), build it
# from source and keep that build in actions/cache under the same key. It lives
# outside cargo's target dir (bin/): rust-cache's post-step cleans bin/.
- name: C++ reference key
id: cppkey
shell: bash
run: echo "key=$(scripts/cpp-ref-key.sh)" >> "$GITHUB_OUTPUT"
- name: Restore C++ reference built from source
uses: actions/cache/restore@v4
with:
path: .cpp
key: cpp-v3-${{ runner.os }}-${{ steps.cppkey.outputs.key }}
- name: Fetch C++ reference (build it when no prebuilt matches)
id: cpp
shell: bash
run: |
cpp=$SOLIDCORE_CPP_DIR
if [ -f "$cpp/lib/libSMLib.a" ] && [ -f "$cpp/lib/libSM_API.a" ] && [ -f "$cpp/ffi.env" ]; then
echo "C++ reference restored from cache"
exit 0
fi
command -v zstd >/dev/null || sudo apt-get install -y zstd
rc=0
scripts/fetch-cpp.sh --no-build || rc=$?
if [ "$rc" = 3 ]; then
sudo apt-get update && sudo apt-get install -y ninja-build cmake g++
harness/cpp/build.sh --no-tests --jobs "$(nproc)"
echo "built=true" >> "$GITHUB_OUTPUT"
elif [ "$rc" != 0 ]; then
exit "$rc"
fi
# Several jobs may build the same key at once; only the first save wins, the
# others log a warning.
- name: Save C++ reference built from source
if: steps.cpp.outputs.built == 'true'
uses: actions/cache/save@v4
continue-on-error: true
with:
path: .cpp
key: cpp-v3-${{ runner.os }}-${{ steps.cppkey.outputs.key }}