blob: f0fd3e263ad536764b3ff33e7d8a3bbba78d48e4 [file]
# SPDX-License-Identifier: MPL-2.0
#
# libpathrs: safe path resolution on Linux
# Copyright (C) 2019-2025 SUSE LLC
# Copyright (C) 2026 Aleksa Sarai <cyphar@cyphar.com>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
on:
push:
branches: [ main ]
tags:
- 'v*'
pull_request:
branches: [ main ]
release:
types: [ published ]
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
name: rust-ci
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
RUST_MSRV: &RUST_MSRV "1.63"
# Pin the Rust version to avoid Rust updates breaking our clippy lints.
# renovate: datasource=rust-version depName=rust extractVersion=^(?<version>\d+\.\d+)\.\d+$
RUST_CLIPPY_VERSION: "1.99"
# renovate: datasource=crate depName=cbindgen
CBINDGEN_VERSION: "0.29.2"
# renovate: datasource=crate depName=cargo-hack
CARGO_HACK_VERSION: "0.6.45"
# renovate: datasource=crate depName=cargo-llvm-cov
CARGO_LLVM_COV_VERSION: "0.8.7"
# renovate: datasource=crate depName=cargo-nextest
CARGO_NEXTEST_VERSION: "0.9.140"
# renovate: datasource=crate depName=cargo-binutils
CARGO_BINUTILS_VERSION: "0.4.0"
# renovate: datasource=github-releases depName=docker/buildx
BUILDX_VERSION: "v0.38.0"
# renovate: datasource=github-releases depName=codecov/codecov-cli
CODECOV_CLI_VERSION: "v11.3.1"
CI_IMAGE: cyphar/libpathrs:ci-latest
jobs:
codespell:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: install codespell
uses: $/.github/actions/python-deps
with:
name: codespell
- run: codespell -L crate
check:
name: cargo check (stable)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: install rust toolchain
run: |-
rustup toolchain install --profile minimal --no-self-update stable
rustup default stable
- uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
with:
tool: cargo-hack@${{ env.CARGO_HACK_VERSION }}
- name: cargo check
run: >-
cargo hack --workspace --each-feature --keep-going \
check --all-targets
check-msrv:
name: cargo check (msrv)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: install rust toolchain
run: |-
rustup toolchain install --profile minimal --no-self-update "$RUST_MSRV"
rustup default "$RUST_MSRV"
- uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
with:
tool: cargo-hack@${{ env.CARGO_HACK_VERSION }}
- name: cargo check
run: >-
cargo hack --each-feature --keep-going \
check --all-targets
check-cross:
strategy:
fail-fast: false
matrix:
target:
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
- aarch64-unknown-linux-musl
- arm-unknown-linux-gnueabi
- arm-unknown-linux-musleabi
- arm-unknown-linux-gnueabihf
- arm-unknown-linux-musleabihf
- armv7-unknown-linux-gnueabi
- armv7-unknown-linux-musleabi
- armv7-unknown-linux-gnueabihf
- armv7-unknown-linux-musleabihf
- i686-unknown-linux-gnu
- loongarch64-unknown-linux-gnu
- loongarch64-unknown-linux-musl
- powerpc-unknown-linux-gnu
- powerpc64-unknown-linux-gnu
- powerpc64-unknown-linux-musl
- powerpc64le-unknown-linux-gnu
- powerpc64le-unknown-linux-musl
- riscv64gc-unknown-linux-gnu
- riscv64gc-unknown-linux-musl
- sparc64-unknown-linux-gnu
- s390x-unknown-linux-gnu
include:
# rustup does not distribute a pre-built libstd for tier 3 targets,
# so we need to use nightly Rust and build libstd ourselves with
# -Zbuild-std.
# NOTE: Adding new targets here from tier 3 is a little risky as they
# may break randomly. Only add a target here if it really is known to
# be needed by someone.
- target: s390x-unknown-linux-musl
build-std: true
# FIXME: This broke with nightly-2026-10-19 (07e526db9).
#- target: riscv32gc-unknown-linux-gnu
# build-std: true
name: cargo check (${{ matrix.target }})
# ubuntu-24.04 lacks an unversioned loongarch64 cross-compiler package.
runs-on: ubuntu-26.04
env:
# Only set for the targets where we need to build libstd ourselves.
BUILD_STD_FLAGS: ${{ matrix.build-std && '-Zbuild-std' || '' }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: install rust toolchain
if: ${{ !matrix.build-std }}
# TODO: Should we use MSRV for this?
env:
RUST_TARGET: ${{ matrix.target }}
run: |-
rustup toolchain install --profile minimal --no-self-update -t "$RUST_TARGET" stable
rustup default stable
# -Zbuild-std requires nightly Rust (and the libstd sources).
- name: install rust toolchain
if: ${{ matrix.build-std }}
run: |-
rustup toolchain install --profile minimal --no-self-update -c rust-src --allow-downgrade nightly
rustup default nightly
- uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
with:
tool: cargo-hack@${{ env.CARGO_HACK_VERSION }}
- name: cargo check --target=${{ matrix.target }}
run: |-
# shellcheck disable=SC2086 # BUILD_STD_FLAGS may be empty.
cargo hack --each-feature --keep-going \
check --target=${{ matrix.target }} --all-targets \
$BUILD_STD_FLAGS
- name: cargo build --target=${{ matrix.target }}
run: |-
# shellcheck disable=SC2086 # BUILD_STD_FLAGS may be empty.
cargo hack --each-feature --keep-going \
build --target=${{ matrix.target }} --release \
$BUILD_STD_FLAGS
# The above only builds an rlib, so the cdylib linking (with our symbol
# versioning setup) is not tested. Linking needs a cross-compiler and a
# libc for the target, which Ubuntu only provides for glibc targets.
# (musl targets default to crt-static, for which cdylibs are not built.)
- name: install cross linker
id: cross-linker
env:
RUST_TARGET: ${{ matrix.target }}
run: |-
case "$RUST_TARGET" in
riscv32*) exit 0 ;; # no Ubuntu cross-compiler
# lld does not support all SPARC relocations used by the gcc crt*.o.
sparc*) exit 0 ;;
*-linux-gnu*) ;;
*) exit 0 ;;
esac
triple="${RUST_TARGET/-unknown-/-}"
triple="${triple/#armv7-/arm-}"
triple="${triple/#riscv64gc-/riscv64-}"
pkgs=(lld binutils-multiarch)
[ "$triple" = "$(gcc -dumpmachine)" ] || pkgs+=("gcc-${triple//_/-}")
sudo apt-get update -y
sudo apt-get install -y "${pkgs[@]}"
# Cross gcc looks for a target-prefixed ld.lld with -fuse-ld=lld.
sudo ln -sf "$(command -v ld.lld)" "/usr/local/bin/$triple-ld.lld"
linker_var="CARGO_TARGET_${RUST_TARGET//-/_}_LINKER"
echo "${linker_var^^}=$triple-gcc" >> "$GITHUB_ENV"
echo "enabled=true" >> "$GITHUB_OUTPUT"
# See the symver! macro for the list of architectures where we
# cannot generate symbol versions yet.
case "$RUST_TARGET" in
powerpc*) ;;
*) echo "symvers=true" >> "$GITHUB_OUTPUT" ;;
esac
- name: make release (cross)
if: steps.cross-linker.outputs.enabled
env:
CARGO_BUILD_TARGET: ${{ matrix.target }}
run: make release
- name: check libpathrs.so symbol versions (cross)
if: steps.cross-linker.outputs.symvers
run: ./hack/check-elf-symbols.sh "target/${{ matrix.target }}/release/libpathrs.so"
check-release-script:
name: check release script
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: compute libpathrs crate version
run: |-
CRATE_VERSION="$(cargo metadata --no-deps --format-version=1 | jq -rM '.packages[] | select(.name == "pathrs") | .version')"
echo "CRATE_VERSION=$CRATE_VERSION" >>"$GITHUB_ENV"
- run: ./hack/release.sh
- run: tar tvf "./release/$CRATE_VERSION/libpathrs-$CRATE_VERSION.tar.xz"
- run: tar tvf "./release/$CRATE_VERSION/libpathrs.vendor.tar.zst"
fmt:
name: rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# We need to use nightly Rust to check the formatting.
- name: install rust toolchain
run: |-
rustup toolchain install --profile minimal --no-self-update -c rustfmt --allow-downgrade nightly
rustup default nightly
- run: cargo fmt --all -- --check
clippy:
name: clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: install rust toolchain
run: |-
rustup toolchain install --profile minimal --no-self-update -c clippy "$RUST_CLIPPY_VERSION"
rustup default "$RUST_CLIPPY_VERSION"
- uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
with:
tool: cargo-hack@${{ env.CARGO_HACK_VERSION }}
- name: cargo clippy
run: >-
cargo hack --workspace --each-feature --keep-going \
clippy --all-targets
check-lint-nohack:
name: make lint (no cargo-hack)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: install rust toolchain
run: |-
rustup toolchain install --profile minimal --no-self-update -c rustfmt -c clippy stable
rustup default stable
- name: install cbindgen
run: cargo install --force --locked cbindgen@${{ env.CBINDGEN_VERSION }}
- name: make lint
run: make CARGO_NIGHTLY=cargo lint
validate-cbindgen:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: install rust toolchain
run: |-
rustup toolchain install --profile minimal --no-self-update stable
rustup default stable
- name: install cbindgen
run: cargo install --force --locked cbindgen@${{ env.CBINDGEN_VERSION }}
- run: make validate-cbindgen
validate-elf-symbols:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust-version:
- *RUST_MSRV
- "1.72" # loongarch64 global_asm! stabilised
- "1.84" # arm64ex / s390x global_asm! stabilised
- "1.91" # loongarch32 global_asm! stabilised
- stable
- nightly
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: install rust toolchain
env:
RUST_TOOLCHAIN: ${{ matrix.rust-version }}
run: |-
rustup toolchain install --profile minimal --no-self-update "$RUST_TOOLCHAIN"
rustup default "$RUST_TOOLCHAIN"
- name: install lld
run: sudo apt-get install -y lld
- run: make validate-elf-symbols
validate-keyring:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- run: make validate-keyring
validate-dist-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: install rust toolchain
run: |-
rustup toolchain install --profile minimal --no-self-update stable
rustup default stable
- run: make dist-release
- name: check release artefacts
run: |-
ls -la release/*/
cat release/*/libpathrs.sha256sum
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust-version:
- *RUST_MSRV # debian bookworm (oldstable)
- "1.75" # centos stream 8
- "1.85" # debian trixie (stable)
- stable
- nightly
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: install rust toolchain
env:
RUST_TOOLCHAIN: ${{ matrix.rust-version }}
run: |-
rustup toolchain install --profile minimal --no-self-update "$RUST_TOOLCHAIN"
rustup default "$RUST_TOOLCHAIN"
- name: install lld
run: sudo apt-get install -y lld
- run: make debug
- run: make release
- if: matrix.rust-version == 'nightly'
name: make release LIBPATHRS_LIBSTD_NO_BACKTRACE=1
run: |
rustup component add rust-src
make clean
make release LIBPATHRS_LIBSTD_NO_BACKTRACE=1
rustdoc:
name: cargo doc
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: install rust toolchain
run: |-
rustup toolchain install --profile minimal --no-self-update stable
rustup default stable
- run: cargo doc --document-private-items --workspace --all-features
- name: upload docs
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: rustdoc
path: target/doc
nextest-archive:
strategy:
fail-fast: false
matrix:
run-as:
- unpriv
- root
name: cargo nextest archive (${{ matrix.run-as }})
runs-on: ubuntu-latest
env:
FEATURES: >-
capi
_test_race
${{ matrix.run-as == 'root' && '_test_as_root _test_can_mknod' || '' }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Nightly rust is required for llvm-cov --doc.
- name: install rust toolchain
run: |-
rustup toolchain install --profile minimal --no-self-update -c llvm-tools --allow-downgrade nightly
rustup default nightly
- uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
with:
tool: cargo-llvm-cov@${{ env.CARGO_LLVM_COV_VERSION }}
- uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
with:
tool: nextest@${{ env.CARGO_NEXTEST_VERSION }}
- name: cargo nextest archive
run: >-
cargo llvm-cov \
nextest-archive \
--workspace \
-F "$FEATURES" \
--archive-file nextest-pathrs-${{ matrix.run-as }}.tar.zst
- name: upload nextest archive
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: nextest-archive-${{ matrix.run-as }}
path: nextest-pathrs-${{ matrix.run-as }}.tar.zst
retention-days: 7 # no need to waste disk space
doctest:
name: cargo test --doc
runs-on: ubuntu-latest
env:
CARGO_NIGHTLY: cargo
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Nightly rust is required for llvm-cov --doc.
- name: install rust toolchain
run: |-
rustup toolchain install --profile minimal --no-self-update -c llvm-tools --allow-downgrade nightly
rustup default nightly
- uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
with:
tool: cargo-llvm-cov@${{ env.CARGO_LLVM_COV_VERSION }}
- run: make test-rust-doctest
- name: upload rust coverage (artifact)
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: profraw-${{ github.job }}-${{ strategy.job-index }}
path: "target/llvm-cov-target/*.profraw"
retention-days: 7 # no need to waste disk space
# TODO: Upload to CodeCov. Unfortunately, "cargo test --doc" does not
# generate a binary that llvm-cov can use to generate coverage reports
# from.
compute-test-partitions:
name: compute test partitions
runs-on: ubuntu-latest
outputs:
tests: ${{ steps.test-partitions.outputs.data }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: compute test partitions
id: test-partitions
run: |-
# Compute the default test set then convert each object to a string
# so that we can double-fromJSON it (once as a list for
# test.strategy, and once again for test.name and the actual test).
partitions="$(./hack/ci-compute-test-partition.jq <<<"null")"
jq -CS <<<"$partitions" # for debugging
echo "data=$(jq -ScM 'map("\(.)")' <<<"$partitions")" >>"$GITHUB_OUTPUT"
nextest:
runs-on: ubuntu-latest
needs:
- compute-test-partitions
- nextest-archive
strategy:
fail-fast: false
matrix:
tests: ${{ fromJSON(needs.compute-test-partitions.outputs.tests) }}
run-as:
- unpriv
- root
enosys:
- ""
- openat2
- statx
exclude:
# The statx tests are quite slow with statx disabled, and there is no
# real benefit to including them since the fallback code is tested
# elsewhere and our race tests don't try even to attack fdinfo.
- enosys: statx
tests: >-
{"name":"race","pattern":"test(#tests::test_race*)"}
env:
NEXTEST_PATTERN_SPEC: ${{ fromJSON(matrix.tests).pattern }}
name: >-
cargo nextest
${{
format('({0}, {1}{2})',
fromJSON(matrix.tests).name,
matrix.run-as,
matrix.enosys && format(', {0}=enosys', matrix.enosys) || ''
)
}}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Nightly rust is required for llvm-cov --doc.
- name: install rust toolchain
run: |-
rustup toolchain install --profile minimal --no-self-update -c llvm-tools --allow-downgrade nightly
rustup default nightly
- uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
with:
tool: cargo-llvm-cov@${{ env.CARGO_LLVM_COV_VERSION }}
- uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
with:
tool: nextest@${{ env.CARGO_NEXTEST_VERSION }}
- name: install llvm-tools wrappers
uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
with:
tool: cargo-binutils@${{ env.CARGO_BINUTILS_VERSION }}
- name: pull nextest archive
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: nextest-archive-${{ matrix.run-as }}
path: .
- name: rust unit tests (${{ matrix.run-as }})
run: >-
./hack/rust-tests.sh \
--cargo=cargo \
${{ matrix.run-as == 'root' && '--sudo' || '' }} \
--enosys="${{ matrix.enosys }}" \
--archive-file="nextest-pathrs-${{ matrix.run-as }}.tar.zst" \
"$NEXTEST_PATTERN_SPEC"
- name: upload rust coverage (artifact)
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: profraw-${{ github.job }}-${{ strategy.job-index }}
path: "target/llvm-cov-target/*.profraw"
retention-days: 7 # no need to waste disk space
# FIXME: llvm-cov appears to have some kind of bug with
# --nextest-archive-file as they do not strip the "target" prefix from
# the nextest archive. As a workaround, we just extract it ourselves.
#
# FIXME: Cargo's v2 build-dir layout (enabled since nightly-2026-07-30)
# causes issues because while both nextest and cargo-llvm-cov support it,
# cargo-llvm-cov depends on a magic "fingerprint" directory being present
# to detect v2 build-dir usage but nextest does not include in its
# archives. We can workaround it for now by creating the directory
# ourselves. See <https://github.com/taiki-e/cargo-llvm-cov/issues/520>.
- name: extract nextest archive
run: |-
tar xv -f nextest-pathrs-${{ matrix.run-as }}.tar.zst -C target/llvm-cov-target/ --strip-components=1
# mkdir -p ./target/llvm-cov-target/debug/build/<crate>/<hash>/fingerprint
find target/llvm-cov-target/debug/build -mindepth 2 -maxdepth 2 -type d -exec mkdir -p '{}/fingerprint' ';'
# Upload to CodeCov.
- name: generate codecov-friendly coverage
id: codecov-coverage
run: |-
CODECOV_FILE="$(mktemp coverage-codecov.lcov.txt.XXXXXX)"
cargo llvm-cov report --lcov --output-path="$CODECOV_FILE"
echo "file=$CODECOV_FILE" >>"$GITHUB_OUTPUT"
- name: upload rust coverage (codecov)
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
version: ${{ env.CODECOV_CLI_VERSION }}
token: ${{ secrets.CODECOV_TOKEN }}
slug: cyphar/libpathrs
files: ${{ steps.codecov-coverage.outputs.file }}
ctr-ci-image:
runs-on: ubuntu-latest
name: build ci docker image
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: setup docker buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
with:
version: ${{ env.BUILDX_VERSION }}
# Avoid GHA cache poisoning of the buildx binary.
cache-binary: false
- name: build and cache ci image
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
tags: ${{ env.CI_IMAGE }}
cache-from: type=gha
cache-to: type=gha,mode=max
ctr-nextest:
runs-on: ubuntu-latest
needs:
- ctr-ci-image
- compute-test-partitions
strategy:
fail-fast: false
matrix:
tests: ${{ fromJSON(needs.compute-test-partitions.outputs.tests) }}
runtime:
- docker
run-as:
- unpriv
- CAP_SYS_ADMIN
env:
NEXTEST_PATTERN_SPEC: ${{ fromJSON(matrix.tests).pattern }}
CONTAINER_RUNTIME: ${{ matrix.runtime }}
# NOTE: For the root tests we need to disable AppArmor because it blocks
# mount operations, even in child mount namespaces.
CONTAINER_RUN_ARGS: >-
${{ matrix.run-as == 'CAP_SYS_ADMIN' && '--cap-add sys_admin --security-opt=apparmor=unconfined' || '' }}
${{ matrix.run-as == 'unpriv' && '--user 1000:1000' || '' }}
name: >-
(${{ matrix.runtime }})
cargo nextest
(${{ fromJSON(matrix.tests).name }}, ${{ matrix.run-as }})
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Nightly rust is required for llvm-cov --doc.
- name: install rust toolchain
run: |-
rustup toolchain install --profile minimal --no-self-update -c llvm-tools --allow-downgrade nightly
rustup default nightly
- uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
with:
tool: cargo-llvm-cov@${{ env.CARGO_LLVM_COV_VERSION }}
- uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
with:
tool: nextest@${{ env.CARGO_NEXTEST_VERSION }}
- name: install llvm-tools wrappers
uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
with:
tool: cargo-binutils@${{ env.CARGO_BINUTILS_VERSION }}
# Pull the image from the cache by triggering a "new build".
- name: setup docker buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
with:
version: ${{ env.BUILDX_VERSION }}
# Avoid GHA cache poisoning of the buildx binary.
cache-binary: false
# TODO: Ideally we would be able to pull the image from the cache without
# needing to trigger another build. In the worst case we could just
# upload the CI image in the ctr-ci-image job and load it here.
- name: build and cache ci image
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
tags: ${{ env.CI_IMAGE }}
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
# Run the tests.
- run: >-
mkdir -p ./target && chmod a+rwx ./target
- name: ${{ matrix.runtime }} run ./hack/rust-tests.sh (run as ${{ matrix.run-as }})
run: |-
# shellcheck disable=SC2086 # CONTAINER_RUN_ARGS needs word-splitting.
"$CONTAINER_RUNTIME" run --rm $CONTAINER_RUN_ARGS \
-v "$PWD/target:/usr/src/libpathrs/target" \
"$CI_IMAGE" \
./hack/rust-tests.sh "$NEXTEST_PATTERN_SPEC"
- run: >-
sudo chown -R "$UID" ./target
- name: upload rust coverage (artifact)
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: profraw-${{ github.job }}-${{ strategy.job-index }}
path: "target/llvm-cov-target/*.profraw"
retention-days: 7 # no need to waste disk space
# Upload to CodeCov.
- name: generate codecov-friendly coverage
id: codecov-coverage
run: |-
CODECOV_FILE="$(mktemp coverage-codecov.lcov.txt.XXXXXX)"
cargo llvm-cov report --lcov --output-path="$CODECOV_FILE"
echo "file=$CODECOV_FILE" >>"$GITHUB_OUTPUT"
- name: upload rust coverage (codecov)
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
version: ${{ env.CODECOV_CLI_VERSION }}
token: ${{ secrets.CODECOV_TOKEN }}
slug: cyphar/libpathrs
files: ${{ steps.codecov-coverage.outputs.file }}
# Smoke-test for our %check section in the libpathrs RPM.
# <https://github.com/cyphar/libpathrs/issues/299>
# TODO: I guess we should run this as root too...
cargo-test:
name: cargo test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: install rust toolchain
run: |-
rustup toolchain install --profile minimal --no-self-update stable
rustup default stable
- name: cargo test
run: cargo test --features capi
coverage:
needs:
- doctest
- nextest
- ctr-nextest
name: compute coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Nightly rust is required for llvm-cov --doc.
- name: install rust toolchain
run: |-
rustup toolchain install --profile minimal --no-self-update -c llvm-tools --allow-downgrade nightly
rustup default nightly
- uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
with:
tool: cargo-llvm-cov@${{ env.CARGO_LLVM_COV_VERSION }}
- name: install llvm-tools wrappers
uses: taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2.87.28
with:
tool: cargo-binutils@${{ env.CARGO_BINUTILS_VERSION }}
- name: pull rust coverage
id: rust-coverage
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: "profraw-*"
path: profraw
- name: merge coverage
env:
PROFRAW_DOWNLOAD_PATH: ${{ steps.rust-coverage.outputs.download-path }}
run: |-
mkdir -p target/llvm-cov-target
profraw_list="$(mktemp --tmpdir libpathrs-profraw.XXXXXXXX)"
find "$PROFRAW_DOWNLOAD_PATH" -name '*.profraw' -type f >"$profraw_list"
rust-profdata merge --sparse -f "$profraw_list" -o ./target/llvm-cov-target/libpathrs-combined.profraw
- name: upload merged rust coverage
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: libpathrs-combined-profraw
path: target/llvm-cov-target/libpathrs-combined.profraw
retention-days: 7 # no need to waste disk space
# FIXME: We just pull one version of the archive and use it for
# generating coverage profiles, but this really is not correct because
# the "root" and "unpriv" binaries are different and so the coverage data
# is a little off. See <https://github.com/cyphar/libpathrs/issues/282>.
- name: pull nextest archive
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: nextest-archive-root
path: .
# FIXME: llvm-cov appears to have some kind of bug with
# --nextest-archive-file as they do not strip the "target" prefix from
# the nextest archive. As a workaround, we just extract it ourselves.
#
# FIXME: Cargo's v2 build-dir layout (enabled since nightly-2026-07-30)
# causes issues because while both nextest and cargo-llvm-cov support it,
# cargo-llvm-cov depends on a magic "fingerprint" directory being present
# to detect v2 build-dir usage but nextest does not include in its
# archives. We can workaround it for now by creating the directory
# ourselves. See <https://github.com/taiki-e/cargo-llvm-cov/issues/520>.
- name: extract nextest archive
run: |-
tar xv -f nextest-pathrs-root.tar.zst -C target/llvm-cov-target/ --strip-components=1
# mkdir -p ./target/llvm-cov-target/debug/build/<crate>/<hash>/fingerprint
find target/llvm-cov-target/debug/build -mindepth 2 -maxdepth 2 -type d -exec mkdir -p '{}/fingerprint' ';'
- name: calculate coverage
run: cargo llvm-cov report
- name: generate coverage html
run: cargo llvm-cov report --html
- name: upload coverage html
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: coverage-report
path: target/llvm-cov/html
examples:
name: smoke-test examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: install rust toolchain
run: |-
rustup toolchain install --profile minimal --no-self-update stable
rustup default stable
- run: cargo build --examples
- run: make -C examples smoke-test-rust
size:
permissions:
contents: read
statuses: write
strategy:
fail-fast: false
matrix:
libtype: [ "cdylib", "staticlib" ]
name: check ${{ matrix.libtype }} size
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: install rust toolchain
run: |-
rustup toolchain install --profile minimal --no-self-update stable
rustup default stable
- run: make release
- name: compute ${{ matrix.libtype }} file name
run: |-
case "${{ matrix.libtype }}" in
cdylib)
libfile=libpathrs.so ;;
staticlib)
libfile=libpathrs.a ;;
*)
exit 1 ;;
esac
echo "LIB_FILENAME=$libfile" >>"$GITHUB_ENV"
- name: strip ${{ matrix.libtype }}
run: |-
cp "target/release/$LIB_FILENAME"{,.nostrip}
strip "target/release/$LIB_FILENAME"
- name: compute ${{ matrix.libtype }} binary size
run: |-
LIB_SIZE="$(stat -c "%s" "target/release/$LIB_FILENAME" | numfmt --to=si --suffix=B)"
LIB_NOSTRIP_SIZE="$(stat -c "%s" "target/release/$LIB_FILENAME.nostrip" | numfmt --to=si --suffix=B)"
cat >&2 <<-EOF
=== binary sizes ===
$LIB_FILENAME Size: $LIB_SIZE
Unstripped: $LIB_NOSTRIP_SIZE
EOF
echo "LIB_SIZE=$LIB_SIZE" >>"$GITHUB_ENV"
echo "LIB_NOSTRIP_SIZE=$LIB_NOSTRIP_SIZE" >>"$GITHUB_ENV"
# At the moment, we can only attach the commit status for push operations
# because pull requests don't get the right permissions in the default
# GITHUB_TOKEN. It's not really clear to me how we should work around
# this (secrets like access tokens are not provided for PRs from forked
# repos) -- we probably need to switch to status checks?
- if: github.event_name == 'push'
name: update commit status
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LIB_TYPE: ${{ matrix.libtype }}
run: |-
gh api --method POST "repos/$GITHUB_REPOSITORY/statuses/$GITHUB_SHA" \
-f state=success \
-f description="$LIB_FILENAME ($LIB_TYPE) is $LIB_SIZE ($LIB_NOSTRIP_SIZE unstripped)" \
-f context="rust-ci / $LIB_TYPE size"
rust-complete:
needs:
- codespell
- check
- check-msrv
- check-cross
- check-release-script
- fmt
- clippy
- check-lint-nohack
- validate-cbindgen
- validate-elf-symbols
- validate-keyring
- validate-dist-release
- build
- rustdoc
- doctest
- nextest
- ctr-nextest
- cargo-test
- coverage
- examples
- size
runs-on: ubuntu-latest
steps:
- run: echo "Rust CI jobs completed successfully."