diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ed8cbc3f..bc185b54 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,6 +3,14 @@ "image": "git.haxx.space/sjg/trx-rs/sdk:latest", "workspaceFolder": "/work", "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": { "vscode": { "extensions": [ diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index ff587761..be432c25 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -16,6 +16,13 @@ on: env: 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: lint: @@ -27,6 +34,9 @@ jobs: run: cargo fmt --all -- --check - name: clippy run: cargo clippy --workspace --all-targets --all-features -- -D warnings + - name: sccache stats + if: always() + run: sccache --show-stats test: runs-on: ubuntu-latest @@ -37,6 +47,9 @@ jobs: run: cargo build --workspace --all-targets --locked - name: Test run: cargo test --workspace --locked + - name: sccache stats + if: always() + run: sccache --show-stats frontend: runs-on: ubuntu-latest diff --git a/container/Containerfile b/container/Containerfile index b882f8a3..4634b52f 100644 --- a/container/Containerfile +++ b/container/Containerfile @@ -43,4 +43,13 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \ --component rustfmt --component clippy \ && 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 diff --git a/container/README.md b/container/README.md index 8937d7a9..dac690f9 100644 --- a/container/README.md +++ b/container/README.md @@ -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 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) The runner uses the **Docker executor** (not the host executor): per-job diff --git a/container/runner-config.example.yaml b/container/runner-config.example.yaml index 03f6cb76..5d49bf8e 100644 --- a/container/runner-config.example.yaml +++ b/container/runner-config.example.yaml @@ -27,7 +27,9 @@ cache: container: # Cap every job container's CPU so CI stays within the 2-thread budget even - # if capacity is raised later. - options: "--cpus=2" + # if capacity is raised later. The -v mount persists the sccache cache on the + # 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. network: "host"