38 lines
1.0 KiB
Bash
38 lines
1.0 KiB
Bash
#!/usr/bin/env bash
|
|
# SPDX-License-Identifier: MIT
|
|
# Reuse Rust compiler results on persistent CI runners.
|
|
set -euo pipefail
|
|
|
|
[ "$(sccache --version)" = 'sccache 0.18.0' ] || {
|
|
echo 'CI image has an unexpected sccache version' >&2
|
|
exit 1
|
|
}
|
|
|
|
toolcache="${RUNNER_TOOL_CACHE:-}"
|
|
if [ -z "$toolcache" ] || [ -L "$toolcache" ] ||
|
|
[ ! -d "$toolcache" ] || [ ! -w "$toolcache" ]; then
|
|
echo 'Persistent runner tool cache is unavailable; compiling without sccache'
|
|
exit 0
|
|
fi
|
|
|
|
cache_dir="$toolcache/alkane-toolkit-rust-sccache"
|
|
if [ -L "$cache_dir" ]; then
|
|
echo 'Rust cache path is a symlink' >&2
|
|
exit 1
|
|
fi
|
|
umask 077
|
|
mkdir -p "$cache_dir"
|
|
if [ ! -d "$cache_dir" ] || [ ! -w "$cache_dir" ]; then
|
|
echo 'Rust cache directory is unavailable' >&2
|
|
exit 1
|
|
fi
|
|
chmod 0700 "$cache_dir"
|
|
|
|
{
|
|
printf 'RUSTC_WRAPPER=%s\n' "$(command -v sccache)"
|
|
printf 'SCCACHE_DIR=%s\n' "$cache_dir"
|
|
printf 'SCCACHE_CACHE_SIZE=2G\n'
|
|
printf 'CARGO_INCREMENTAL=0\n'
|
|
} >> "${GITHUB_ENV:?GITHUB_ENV is required}"
|
|
echo 'Bounded Rust compiler cache configured for Alkane Toolkit'
|