Build scripts that compile C/C++ (cc crate, libduckdb-sys's bundled DuckDB, ring's assembly) are not cached by RUSTC_WRAPPER and dominate warm CI time on Rust projects with heavy native deps. Export CC=sccache cc and CXX=sccache c++ so those compilations land in the same sccache backend as rustc. Gated behind a new sccache-wrap-cc input (default "true") so callers with build systems that do not tolerate multi-word CC/CXX can opt out. Co-authored-by: Cursor <cursoragent@cursor.com>
3.2 KiB
3.2 KiB
actions-rust
Reusable Gitea Actions for Rust projects.
actions/rust-cache
Composite action that installs Rust, installs a prebuilt Mozilla sccache
binary, and configures RUSTC_WRAPPER=sccache for later Cargo steps.
This action intentionally does not use Gitea actions/cache and does not cache
target/. Rust build artifacts are cached through sccache; callers can use
local sccache storage or an S3-compatible backend.
S3 usage
Create one shared bucket for Rust compiler artifacts, then pass non-secret S3 settings as inputs and credentials as normal workflow secrets.
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Rust + sccache
uses: https://git.ericxliu.me/eric/actions-rust/.gitea/actions/rust-cache@main
with:
toolchain: stable
sccache-bucket: sccache
sccache-region: auto
sccache-endpoint: https://s3.example.com
sccache-key-prefix: my-org/my-repo/linux-x64/stable
env:
AWS_ACCESS_KEY_ID: ${{ secrets.SCCACHE_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.SCCACHE_AWS_SECRET_ACCESS_KEY }}
- run: cargo test
- run: sccache --show-stats
Local usage
Omit sccache-bucket to use the runner-local sccache cache:
- name: Setup Rust + local sccache
uses: https://git.ericxliu.me/eric/actions-rust/.gitea/actions/rust-cache@main
with:
toolchain: stable
Inputs
toolchain: Rust toolchain to install. Defaults tostable.sccache: Set to"false"to install Rust without configuring sccache.sccache-version: Mozilla sccache release tag. Defaults tov0.15.0.sccache-bucket: S3 bucket name. Empty means local sccache storage.sccache-region: S3 region. For S3-compatible endpoints,autois usually right.sccache-endpoint: Optional S3-compatible endpoint URL.sccache-s3-use-ssl: Whether the endpoint uses TLS. Defaults to"true".sccache-s3-enable-virtual-host-style: Set to"true"only for endpoints that require virtual-host-style addressing.sccache-key-prefix: Optional cache key prefix. Defaults to repository, runner, and toolchain scope.sccache-wrap-cc: WrapCCandCXXwith sccache so build-script C/C++ compiles (e.g.libduckdb-sys,ring) hit the cache too. Defaults to"true". Set to"false"to opt out.
Notes
- Do not pass secret values as action inputs. Pass standard AWS environment variables from workflow secrets.
CARGO_INCREMENTAL=0is set because Rust incremental artifacts are not a good fit for sccache-backed CI builds.- When
sccache-wrap-ccis enabled,CCis exported assccache ccandCXXassccache c++. Thecccrate splits on whitespace, so build scripts that go through it pick up the wrapper transparently. Build systems that do not support multi-wordCC/CXXshould opt out. SCCACHE_IGNORE_SERVER_IO_ERROR=1is set so a cache outage falls back to local compilation instead of failing the build.SCCACHE_IDLE_TIMEOUT=3600keeps the server alive across long build/test steps, which matters when the setup step has S3 credentials scoped only to that step.- Add
sccache --show-statsafter build/test steps to inspect cache hit rates.