Files
actions-rust/.gitea/actions/rust-cache/action.yml
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

137 lines
5.1 KiB
YAML

name: Rust Setup + Sccache
description: Install Rust and configure sccache for Rust builds in Gitea Actions
author: eric
inputs:
toolchain:
description: Rust toolchain to install (e.g., stable, 1.75.0, nightly)
default: stable
required: false
sccache:
description: Enable sccache and set RUSTC_WRAPPER.
default: "true"
required: false
sccache-version:
description: Mozilla sccache release tag to install.
default: v0.15.0
required: false
sccache-bucket:
description: S3 bucket for sccache. Leave empty to use local sccache storage.
default: ""
required: false
sccache-region:
description: S3 region. Use auto for S3-compatible services when an endpoint is provided.
default: auto
required: false
sccache-endpoint:
description: Optional S3-compatible endpoint URL, for example https://s3.example.com.
default: ""
required: false
sccache-s3-use-ssl:
description: Whether the S3 endpoint uses TLS.
default: "true"
required: false
sccache-s3-enable-virtual-host-style:
description: Enable virtual-host-style S3 addressing.
default: "false"
required: false
sccache-key-prefix:
description: Optional S3 key prefix. Defaults to repository/runner/toolchain scope.
default: ""
required: false
sccache-wrap-cc:
description: Also wrap CC and CXX with sccache so build-script C/C++ compiles (e.g. libduckdb-sys, ring) hit the same cache as rustc. Set to "false" to opt out.
default: "true"
required: false
outputs:
sccache-enabled:
description: Whether sccache was enabled.
value: ${{ steps.configure-sccache.outputs.enabled }}
runs:
using: composite
steps:
- name: Setup Rust
shell: bash
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| sh -s -- -y --profile minimal --default-toolchain '${{ inputs.toolchain }}'
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
- name: Install sccache
if: ${{ inputs.sccache == 'true' }}
shell: bash
run: |
set -euo pipefail
version='${{ inputs.sccache-version }}'
case "$(uname -s)-$(uname -m)" in
Linux-x86_64) target=x86_64-unknown-linux-musl ;;
Linux-aarch64|Linux-arm64) target=aarch64-unknown-linux-musl ;;
Darwin-x86_64) target=x86_64-apple-darwin ;;
Darwin-arm64|Darwin-aarch64) target=aarch64-apple-darwin ;;
*)
echo "unsupported sccache platform: $(uname -s)-$(uname -m)" >&2
exit 1
;;
esac
asset="sccache-${version}-${target}.tar.gz"
base_url="https://github.com/mozilla/sccache/releases/download/${version}"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
curl -fsSLo "$tmp/$asset" "$base_url/$asset"
curl -fsSLo "$tmp/$asset.sha256" "$base_url/$asset.sha256"
expected="$(tr -d '[:space:]' < "$tmp/$asset.sha256")"
if command -v sha256sum >/dev/null 2>&1; then
actual="$(sha256sum "$tmp/$asset" | cut -d ' ' -f 1)"
else
actual="$(shasum -a 256 "$tmp/$asset" | cut -d ' ' -f 1)"
fi
test "$expected" = "$actual"
tar -xzf "$tmp/$asset" -C "$tmp"
install -m 755 "$(find "$tmp" -type f -name sccache | head -n 1)" "$HOME/.cargo/bin/sccache"
sccache --version
- name: Configure sccache
id: configure-sccache
if: ${{ inputs.sccache == 'true' }}
shell: bash
run: |
set -euo pipefail
echo "enabled=true" >> "$GITHUB_OUTPUT"
echo "RUSTC_WRAPPER=sccache" >> "$GITHUB_ENV"
echo "CARGO_INCREMENTAL=0" >> "$GITHUB_ENV"
echo "SCCACHE_IGNORE_SERVER_IO_ERROR=1" >> "$GITHUB_ENV"
echo "SCCACHE_IDLE_TIMEOUT=3600" >> "$GITHUB_ENV"
echo "SCCACHE_LOG=${SCCACHE_LOG:-warn}" >> "$GITHUB_ENV"
if [ -n '${{ inputs.sccache-bucket }}' ]; then
repo="${GITHUB_REPOSITORY:-unknown/repository}"
runner_os="${RUNNER_OS:-$(uname -s)}"
runner_arch="${RUNNER_ARCH:-$(uname -m)}"
prefix='${{ inputs.sccache-key-prefix }}'
if [ -z "$prefix" ]; then
prefix="$repo/$runner_os-$runner_arch/${{ inputs.toolchain }}"
fi
echo "SCCACHE_BUCKET=${{ inputs.sccache-bucket }}" >> "$GITHUB_ENV"
echo "SCCACHE_REGION=${{ inputs.sccache-region }}" >> "$GITHUB_ENV"
echo "SCCACHE_S3_USE_SSL=${{ inputs.sccache-s3-use-ssl }}" >> "$GITHUB_ENV"
echo "SCCACHE_S3_KEY_PREFIX=$prefix" >> "$GITHUB_ENV"
if [ -n '${{ inputs.sccache-endpoint }}' ]; then
echo "SCCACHE_ENDPOINT=${{ inputs.sccache-endpoint }}" >> "$GITHUB_ENV"
fi
if [ '${{ inputs.sccache-s3-enable-virtual-host-style }}' = 'true' ]; then
echo "SCCACHE_S3_ENABLE_VIRTUAL_HOST_STYLE=true" >> "$GITHUB_ENV"
fi
fi
if [ '${{ inputs.sccache-wrap-cc }}' = 'true' ]; then
echo "CC=sccache cc" >> "$GITHUB_ENV"
echo "CXX=sccache c++" >> "$GITHUB_ENV"
fi
- name: Start sccache
if: ${{ inputs.sccache == 'true' }}
shell: bash
run: |
sccache --start-server
sccache --show-stats