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 SOLIDCORE_CPP_DIR in the job environment; the upstream pin (UPSTREAM_REPO, UPSTREAM_VERSION, UPSTREAM_COMMIT) comes from scripts/upstream-pin.env unless the job environment already sets it. runs: using: composite steps: - name: Load upstream pin shell: bash run: | while IFS='=' read -r k v; do case "$k" in UPSTREAM_REPO|UPSTREAM_VERSION|UPSTREAM_COMMIT) if [ -z "${!k:-}" ]; then echo "$k=$v" >> "$GITHUB_ENV"; fi ;; esac done < scripts/upstream-pin.env - 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. # A pinned version is downloaded straight from the release URL; without one the # action asks the REST API for the latest release on every job, which spends the # repository's GITHUB_TOKEN quota and fails the job once it runs out. - name: Set up sccache uses: mozilla-actions/sccache-action@v0.0.11 with: version: v0.19.0 - 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 }}