[chore](trx-rs): add sccache compilation cache
CI / reuse (pull_request) Successful in 5s
CI / lint (pull_request) Failing after 4s
CI / test (pull_request) Failing after 4s

Bake sccache into the SDK image and enable it via RUSTC_WRAPPER in CI and
the devcontainer (not repo-wide, so non-SDK builds are unaffected).

- container/Containerfile: install the sccache musl binary.
- ci.yml: RUSTC_WRAPPER=sccache, CARGO_INCREMENTAL=0, SCCACHE_DIR=/sccache,
  cache size cap, plus a `sccache --show-stats` step per job.
- runner-config.example.yaml: bind-mount /var/cache/sccache into job
  containers so the cache persists across runs and is shared between jobs.
- .devcontainer: enable sccache with a named cache volume.

Assisted-By: Claude Code (claude-opus-4)
Claude-Session: https://claude.ai/code/session_01NFpGtGTWUEYXLwZeZs2RAV
Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
sjg
2026-07-19 16:43:59 +02:00
parent 9da6118a35
commit 99ae2a5fd7
5 changed files with 50 additions and 2 deletions
+8
View File
@@ -3,6 +3,14 @@
"image": "git.haxx.space/sjg/trx-rs/sdk:latest", "image": "git.haxx.space/sjg/trx-rs/sdk:latest",
"workspaceFolder": "/work", "workspaceFolder": "/work",
"workspaceMount": "source=${localWorkspaceFolder},target=/work,type=bind", "workspaceMount": "source=${localWorkspaceFolder},target=/work,type=bind",
"mounts": [
"source=trx-rs-sccache,target=/sccache,type=volume"
],
"containerEnv": {
"RUSTC_WRAPPER": "sccache",
"CARGO_INCREMENTAL": "0",
"SCCACHE_DIR": "/sccache"
},
"customizations": { "customizations": {
"vscode": { "vscode": {
"extensions": [ "extensions": [
+13
View File
@@ -16,6 +16,13 @@ on:
env: env:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
# sccache: shared compilation cache persisted on the runner host (see the
# -v mount in runner-config.example.yaml). CARGO_INCREMENTAL=0 because
# sccache cannot cache incremental artifacts.
RUSTC_WRAPPER: sccache
CARGO_INCREMENTAL: "0"
SCCACHE_DIR: /sccache
SCCACHE_CACHE_SIZE: "20G"
jobs: jobs:
lint: lint:
@@ -27,6 +34,9 @@ jobs:
run: cargo fmt --all -- --check run: cargo fmt --all -- --check
- name: clippy - name: clippy
run: cargo clippy --workspace --all-targets --all-features -- -D warnings run: cargo clippy --workspace --all-targets --all-features -- -D warnings
- name: sccache stats
if: always()
run: sccache --show-stats
test: test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -37,6 +47,9 @@ jobs:
run: cargo build --workspace --all-targets --locked run: cargo build --workspace --all-targets --locked
- name: Test - name: Test
run: cargo test --workspace --locked run: cargo test --workspace --locked
- name: sccache stats
if: always()
run: sccache --show-stats
reuse: reuse:
runs-on: ubuntu-latest runs-on: ubuntu-latest
+9
View File
@@ -43,4 +43,13 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
--component rustfmt --component clippy \ --component rustfmt --component clippy \
&& chmod -R a+rwX "$RUSTUP_HOME" "$CARGO_HOME" && chmod -R a+rwX "$RUSTUP_HOME" "$CARGO_HOME"
# sccache — shared compilation cache. Enabled at build time via
# RUSTC_WRAPPER (see the CI workflow and .devcontainer), not repo-wide, so
# non-SDK builds are unaffected. musl build is static and runs anywhere.
ARG SCCACHE_VERSION=0.8.2
RUN curl -fsSL "https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz" \
| tar -xz -C /tmp \
&& install -m755 "/tmp/sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl/sccache" /usr/local/bin/sccache \
&& rm -rf /tmp/sccache-*
WORKDIR /work WORKDIR /work
+16
View File
@@ -54,6 +54,22 @@ The `reuse` job stays on the upstream `fsfe/reuse-action` (a Docker action the
Docker executor launches as a sibling container) — nothing REUSE-related is Docker executor launches as a sibling container) — nothing REUSE-related is
baked into the SDK. baked into the SDK.
## Compilation cache (sccache)
The SDK image ships [`sccache`](https://github.com/mozilla/sccache). It is
enabled via `RUSTC_WRAPPER=sccache` in CI and the devcontainer (not repo-wide,
so plain `cargo` builds outside the SDK are unaffected).
- **CI** persists the cache on the runner host — create the dir once:
`mkdir -p /var/cache/sccache`. It is bind-mounted into each job container at
`/sccache` (see `runner-config.example.yaml`), so cache survives across runs
and is shared between the lint/test jobs and both projects.
- **Devcontainer** uses a named volume (`trx-rs-sccache`).
- Check effectiveness with `sccache --show-stats` (the CI jobs print it).
`CARGO_INCREMENTAL=0` is set wherever sccache is on, since sccache cannot cache
incremental artifacts.
## CI runner (Alpine / OpenRC) ## CI runner (Alpine / OpenRC)
The runner uses the **Docker executor** (not the host executor): per-job The runner uses the **Docker executor** (not the host executor): per-job
+4 -2
View File
@@ -27,7 +27,9 @@ cache:
container: container:
# Cap every job container's CPU so CI stays within the 2-thread budget even # Cap every job container's CPU so CI stays within the 2-thread budget even
# if capacity is raised later. # if capacity is raised later. The -v mount persists the sccache cache on the
options: "--cpus=2" # host (create it first: `mkdir -p /var/cache/sccache`), matching SCCACHE_DIR
# in the workflow.
options: "--cpus=2 -v /var/cache/sccache:/sccache"
# Reuse the host VM's Docker network for the built-in cache/artifact server. # Reuse the host VM's Docker network for the built-in cache/artifact server.
network: "host" network: "host"