blob: e01ce81f8de281fe367fa42fe3a7e23daa1bdfa8 [file]
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: setup-rust-with-cache
description: Setup Rust toolchain with Swatinem/rust-cache
inputs:
read-cache:
description: "Whether to read from cache"
required: false
default: "true"
shared-key:
description: "Shared cache key across jobs"
required: false
default: "dev"
save-cache:
description: "Whether to save cache (true/false)"
required: false
default: "false"
free-disk-space:
description: >-
Whether to reclaim runner disk before the build. Default "true".
Set "false" for light legs (fmt/sort/clippy/check/machete/doctest) that
fit in the ~89 GiB default headroom and should not pay the ~20-45s cost.
required: false
default: "true"
free-disk-space-aggressive:
description: >-
Forwarded to free-disk-space. When "true", run jlumbroso for a deep
cleanup. Enable for disk-heavy jobs (e.g. llvm-cov instrumented builds).
required: false
default: "false"
runs:
using: "composite"
steps:
- name: Free runner disk space
if: inputs.free-disk-space == 'true'
uses: ./.github/actions/utils/free-disk-space
with:
aggressive: ${{ inputs.free-disk-space-aggressive }}
- name: Install system dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libhwloc-dev pkg-config libudev-dev
shell: bash
- name: Install system dependencies (macOS)
if: runner.os == 'macOS'
run: |
# Pin version of hwloc to 2.12.2_1
# brew extract doesn't have this version, so we fetch the formula directly
brew tap-new iggy/local-hwloc
curl -fsSL https://raw.githubusercontent.com/Homebrew/homebrew-core/bb1e23f8e5eacf4d31acd489f6079c8a53ebd690/Formula/h/hwloc.rb \
-o "$(brew --repository iggy/local-hwloc)/Formula/hwloc.rb"
brew install iggy/local-hwloc/hwloc
shell: bash
- name: Setup Rust toolchain
run: |
# macOS runners provision Rust via the Homebrew `rustup` formula, which
# installs only `rustup-init` plus brew shims that resolve back to it in
# installer mode - so `cargo` errors out and ~/.cargo/bin has no proxies.
# Run rustup-init once to generate the real cargo/rustc proxies.
if [ "$RUNNER_OS" = "macOS" ]; then
rustup-init -y --no-modify-path --default-toolchain none
fi
rustup show
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
shell: bash
- name: Setup Rust cache
id: rust-cache
if: inputs.read-cache == 'true'
uses: Swatinem/rust-cache@v2
with:
shared-key: ${{ inputs.shared-key }}
save-if: ${{ inputs.save-cache == 'true' }}
- name: Cache status
if: inputs.read-cache == 'true'
run: |
CARGO_HOME_DIR="${CARGO_HOME:-$HOME/.cargo}"
if [ "${{ steps.rust-cache.outputs.cache-hit }}" == "true" ]; then
status="full hit"
elif [ -d "target" ]; then
status="partial hit"
else
status="miss"
fi
# Unpacked on-disk footprint of the restore. The cache action only logs
# the compressed size; this prints to the job log (stdout), so size is
# visible without opening the summary and without annotations.
echo "Rust cache: ${status}"
printf '%-10s %s\n' "SIZE" "PATH"
for dir in "${GITHUB_WORKSPACE}/target" "${CARGO_HOME_DIR}/registry" "${CARGO_HOME_DIR}/git"; do
if [ -d "${dir}" ]; then
printf '%-10s %s\n' "$(du -sh "${dir}" 2>/dev/null | cut -f1)" "${dir/#${GITHUB_WORKSPACE}\//}"
fi
done
shell: bash
- name: Install cargo-nextest
if: runner.os == 'Linux'
run: |
if command -v cargo-nextest &> /dev/null; then
echo "cargo-nextest already installed"
cargo nextest --version
exit 0
fi
ARCH="$(uname -m)"
case "$ARCH" in
x86_64) NEXTEST_PLATFORM="linux" ;;
aarch64) NEXTEST_PLATFORM="linux-arm" ;;
*)
echo "Unsupported architecture: $ARCH, skipping nextest"
exit 0
;;
esac
curl -LsSf "https://get.nexte.st/latest/${NEXTEST_PLATFORM}" | tar xzf - -C ${CARGO_HOME:-~/.cargo}/bin
cargo nextest --version
shell: bash
continue-on-error: true
- name: Configure Cargo for CI
if: inputs.read-cache == 'true'
run: |
echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV
echo "CARGO_PROFILE_DEV_DEBUG=0" >> $GITHUB_ENV
echo "CARGO_PROFILE_TEST_DEBUG=0" >> $GITHUB_ENV
echo "CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse" >> $GITHUB_ENV
shell: bash