Files
actions-rust/README.md
Eric Liu a83a6d8f5c Wrap CC and CXX with sccache by default
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>
2026-05-05 21:56:32 -07:00

82 lines
3.2 KiB
Markdown

# 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.
```yaml
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:
```yaml
- 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 to `stable`.
- `sccache`: Set to `"false"` to install Rust without configuring sccache.
- `sccache-version`: Mozilla sccache release tag. Defaults to `v0.15.0`.
- `sccache-bucket`: S3 bucket name. Empty means local sccache storage.
- `sccache-region`: S3 region. For S3-compatible endpoints, `auto` is 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`: Wrap `CC` and `CXX` with 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=0` is set because Rust incremental artifacts are not a
good fit for sccache-backed CI builds.
- When `sccache-wrap-cc` is enabled, `CC` is exported as `sccache cc` and `CXX`
as `sccache c++`. The `cc` crate splits on whitespace, so build scripts that
go through it pick up the wrapper transparently. Build systems that do not
support multi-word `CC`/`CXX` should opt out.
- `SCCACHE_IGNORE_SERVER_IO_ERROR=1` is set so a cache outage falls back to
local compilation instead of failing the build.
- `SCCACHE_IDLE_TIMEOUT=3600` keeps 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-stats` after build/test steps to inspect cache hit rates.