Files
actions-rust/.gitea/actions/rust-cache/action.yml

145 lines
5.5 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_retry() {
curl --http1.1 --retry 5 --retry-all-errors --retry-delay 3 --connect-timeout 20 -fsSLo "$1" "$2"
}
if ! curl_retry "$tmp/$asset" "$base_url/$asset" || ! curl_retry "$tmp/$asset.sha256" "$base_url/$asset.sha256"; then
echo "sccache release download failed; falling back to cargo install" >&2
crate_version="${version#v}"
cargo install sccache --locked --version "$crate_version" --features s3
sccache --version
exit 0
fi
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