feat: enabled cargo target caching and conditional validation in workflows

- Add scripts/ci-target-cache.ts to snapshot and restore Cargo target directories to S3 storage on omp-kata runners.
- Update .github/actions/build-native/action.yml to support target cache restoration, saving, and compiler launcher configurations.
- Add skip_validation input in GitHub workflow actions to bypass clippy and Rust test checks on release runs.
This commit is contained in:
can1357
2026-07-25 02:34:14 +02:00
parent 0491f2961a
commit 59619623e1
5 changed files with 302 additions and 7 deletions
+50 -5
View File
@@ -42,8 +42,17 @@ inputs:
description: Run clippy/rustfmt checks (only one matrix entry should set this)
required: false
default: "false"
skip_validation:
description: >
Skip clippy/rustfmt and the Rust test suite. Set on release runs: the
version-bump commit only changes version strings, and the tagged
content's Rust code already passed validation on its main-push run.
required: false
default: "false"
save_cache:
description: Whether Swatinem/rust-cache should write a cache entry (GitHub-hosted only)
description: >
Whether to write build caches: Swatinem/rust-cache on GitHub-hosted
runners, the RustFS target/ snapshot on omp-kata.
required: false
default: "false"
@@ -186,8 +195,9 @@ runs:
# forever). The native source hash is in the shared key too: rust-cache's
# lockfile scan misses the workspace-root Cargo.toml version Cargo
# fingerprints, so a version bump could otherwise get an exact hit for
# artifacts Cargo must rebuild. On omp-kata the mounted Cargo registry +
# RustFS sccache are the reuse layers, so there is no second cache restore.
# artifacts Cargo must rebuild. On omp-kata the reuse layers are the
# mounted Cargo registry, RustFS sccache, and the RustFS target/ snapshot
# (see "Restore target/ cache" below), so Swatinem stays GitHub-only.
- name: Cache Rust target/ (GitHub-hosted)
if: steps.detect.outputs.on_infra == 'false'
uses: Swatinem/rust-cache@v2
@@ -212,11 +222,23 @@ runs:
# conditional: omp-kata reads the shared S3 (RustFS) config from the
# inherited pod env; GitHub-hosted runners use the GHA cache backend.
shell: bash
env:
CROSS_TARGET: ${{ steps.resolve.outputs.cross_target }}
run: |
{
echo "RUSTC_WRAPPER=sccache"
echo "CARGO_INCREMENTAL=0"
} >> "$GITHUB_ENV"
# Route CMake-built C (audiopus_sys' bundled opus) through sccache
# too — build scripts bypass RUSTC_WRAPPER. Non-cross builds only:
# cross builds compile C with zig cc / clang-cl wrapper scripts that
# sccache may fail to classify, which would hard-fail the compile.
if [ -z "$CROSS_TARGET" ]; then
{
echo "CMAKE_C_COMPILER_LAUNCHER=sccache"
echo "CMAKE_CXX_COMPILER_LAUNCHER=sccache"
} >> "$GITHUB_ENV"
fi
if [ -n "${SCCACHE_BUCKET:-}" ]; then
echo "sccache backend: shared S3 ($SCCACHE_BUCKET @ $SCCACHE_ENDPOINT)"
else
@@ -295,9 +317,23 @@ runs:
shell: bash
run: echo "XWIN_ACCEPT_LICENSE=1" >> "$GITHUB_ENV"
# --- target/ cache (omp-kata) --------------------------------------------
# sccache only covers rustc invocations; build-script outputs (57
# tree-sitter grammar C compiles, bundled opus via CMake, ring asm) and
# cargo's fingerprint/link work bypass it. Snapshot target/ to the same
# RustFS S3 bucket, keyed per platform/libc/arch/variant + toolchain and
# overwritten on each save so storage stays bounded at one snapshot per
# key. GitHub-hosted runners get the same effect from Swatinem above.
- name: Restore target/ cache (omp-kata)
if: steps.detect.outputs.on_infra == 'true'
shell: bash
env:
TARGET_CACHE_KEY: native-${{ inputs.platform }}-${{ inputs.libc || 'default' }}-${{ inputs.arch }}-${{ inputs.variant || 'default' }}
run: bun scripts/ci-target-cache.ts restore "$TARGET_CACHE_KEY"
# --- Checks, build, upload (shared) -------------------------------------
- name: Rust checks
if: inputs.rust_checks == 'true'
if: inputs.rust_checks == 'true' && inputs.skip_validation != 'true'
shell: bash
run: bun run check:rs
- name: Test workspace (Rust)
@@ -305,7 +341,7 @@ runs:
# Windows-only tests are no longer exercised in CI (win32-x64 cross-builds
# on Linux). Skipping the duplicate Linux runs on macOS saves ~10 min of
# parallel runner time.
if: inputs.target == '' && inputs.platform != 'darwin'
if: inputs.target == '' && inputs.platform != 'darwin' && inputs.skip_validation != 'true'
shell: bash
run: bun run test:rs
- name: Build native addon(s)
@@ -316,6 +352,9 @@ runs:
TARGET_ARCH: ${{ inputs.arch }}
TARGET_VARIANTS: ${{ inputs.variant }}
run: bun run ci:build:native
- name: sccache stats
shell: bash
run: sccache --show-stats || true
- name: Upload native addon(s)
uses: actions/upload-artifact@v4
with:
@@ -326,3 +365,9 @@ runs:
# org defaults shift; bump if Rust source ever stays stable for >90 days
# of main pushes and you want to avoid rebuilds.
retention-days: 90
- name: Save target/ cache (omp-kata)
if: steps.detect.outputs.on_infra == 'true' && inputs.save_cache == 'true'
shell: bash
env:
TARGET_CACHE_KEY: native-${{ inputs.platform }}-${{ inputs.libc || 'default' }}-${{ inputs.arch }}-${{ inputs.variant || 'default' }}
run: bun scripts/ci-target-cache.ts save "$TARGET_CACHE_KEY"
+4 -1
View File
@@ -214,7 +214,9 @@ jobs:
# Linux x64 baseline + modern: required by `test`, so it runs on every PR
# unless native_artifact_lookup found a cached run. Release runs always
# rebuild for fresh artifacts.
# rebuild for fresh artifacts but skip clippy + Rust tests (skip_validation):
# the bump commit only changes version strings over content that already
# passed validation on its main-push run.
native_linux_x64:
name: "Native: Linux x64 (${{ matrix.variant }})"
needs: [release_metadata, native_artifact_lookup]
@@ -236,6 +238,7 @@ jobs:
variant: ${{ matrix.variant }}
glibc: ${{ env.GLIBC_FLOOR }}
rust_checks: ${{ matrix.rust_checks && 'true' || 'false' }}
skip_validation: ${{ needs.release_metadata.outputs.is-release }}
save_cache: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
# Pre-warm the cross-platform native build cache on `main`, in addition to