name: CI
on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-D warnings"
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
jobs:
test:
name: Test (${{ matrix.os }} / ${{ matrix.rust }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- ubuntu-24.04-arm
- macos-latest
- macos-15-intel
- windows-latest
- windows-11-arm
rust: [stable, "1.89"]
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
- name: Format
run: cargo fmt --all -- --check
- name: Clippy (default features)
run: cargo clippy --all-targets -- -D warnings
- name: Clippy (all features)
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Clippy (no default features)
run: cargo clippy --all-targets --no-default-features -- -D warnings
- name: Test (default features)
run: cargo test
- name: Test (all features)
run: cargo test --all-features
- name: Test (no default features)
run: cargo test --no-default-features
- name: Name the crashing test
if: failure()
run: cargo test --lib --all-features -- --test-threads=1 --nocapture
- name: Backtrace of the crash (macOS)
if: failure() && runner.os == 'macOS'
run: |
exe=$(cargo test --lib --all-features --no-run --message-format=json | jq -r 'select(.profile.test == true and .target.kind[0] == "lib") | .executable' | head -1)
lldb --batch -o run -k "thread backtrace" -k quit -- "$exe" --test-threads=1 --nocapture
- name: Build examples
run: cargo build --examples
- name: Doc (default features)
run: cargo doc --no-deps
env:
RUSTDOCFLAGS: "-D warnings"
- name: Doc (all features)
run: cargo doc --no-deps --all-features
env:
RUSTDOCFLAGS: "-D warnings"
cross:
name: Check (${{ matrix.target }} / ${{ matrix.rust }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- x86_64-unknown-linux-musl
- i686-unknown-linux-musl
- i686-pc-windows-msvc
- aarch64-linux-android
- aarch64-apple-ios
- x86_64-unknown-freebsd
rust: [stable, "1.89"]
env:
CARGO_FEATURE_PURE: "1"
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
components: clippy
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Check (default features)
run: cargo check --target ${{ matrix.target }}
- name: Check (all features)
run: cargo check --target ${{ matrix.target }} --all-features
- name: Check (no default features)
run: cargo check --target ${{ matrix.target }} --no-default-features
- name: Clippy and layout oracles (all features)
run: cargo clippy --target ${{ matrix.target }} --all-targets --all-features -- -D warnings
- name: Clippy and layout oracles (no default features)
run: cargo clippy --target ${{ matrix.target }} --all-targets --no-default-features -- -D warnings
linux32:
name: Test (${{ matrix.target }} / ${{ matrix.rust }})
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
target: [i686-unknown-linux-gnu, armv7-unknown-linux-gnueabihf]
rust: [stable, "1.89"]
env:
CARGO_FEATURE_PURE: "1"
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER: qemu-arm
QEMU_LD_PREFIX: /usr/arm-linux-gnueabihf
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
components: clippy
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Install the target's C toolchain
run: |
sudo apt-get update
if [ "${{ matrix.target }}" = i686-unknown-linux-gnu ]; then
sudo apt-get install -y gcc-multilib
else
sudo apt-get install -y gcc-arm-linux-gnueabihf libc6-dev-armhf-cross qemu-user qemu-user-binfmt
fi
- name: Clippy and layout oracles (all features)
run: cargo clippy --target ${{ matrix.target }} --all-targets --all-features -- -D warnings
- name: Clippy and layout oracles (no default features)
run: cargo clippy --target ${{ matrix.target }} --all-targets --no-default-features -- -D warnings
- name: Test (all features)
run: cargo test --target ${{ matrix.target }} --all-features
- name: Test (no default features)
run: cargo test --target ${{ matrix.target }} --no-default-features
freebsd:
name: FreeBSD 14 VM (${{ matrix.rust }})
runs-on: ubuntu-latest
timeout-minutes: 75
strategy:
fail-fast: false
matrix:
rust: [stable, "1.89"]
steps:
- uses: actions/checkout@v5
- name: Clippy and tests in FreeBSD
uses: vmactions/freebsd-vm@v1.5.9
env:
RUST_TOOLCHAIN: ${{ matrix.rust }}
CI: "true"
with:
release: "14"
envs: "RUST_TOOLCHAIN CI"
copyback: false
run: |
set -eu
freebsd-version -ku
sysctl kern.vm_guest hw.ncpu hw.physmem kern.timecounter.hardware
pw useradd -n ci -m -s /bin/sh
chown -R ci .
cat > /tmp/ci.sh <<'EOS'
set -eu
# rustup-init itself: the sh.rustup.rs script needs curl or wget,
# which the base system lacks; fetch(1) is in base.
fetch -q -o /tmp/rustup-init https://static.rust-lang.org/rustup/dist/x86_64-unknown-freebsd/rustup-init
chmod +x /tmp/rustup-init
/tmp/rustup-init -y -q --profile minimal --default-toolchain "$1" -c clippy
. "$HOME/.cargo/env"
cd "$2"
export CI=true CARGO_TERM_COLOR=always RUSTFLAGS="-D warnings"
rustc --version
cargo clippy --all-targets -- -D warnings
cargo clippy --all-targets --all-features -- -D warnings
cargo clippy --all-targets --no-default-features -- -D warnings
# Every mode runs to the end, so one log shows every failure.
status=0
cargo test --no-fail-fast || status=1
# A crash in a test thread loses its output: on failure, run the
# unit tests one at a time, uncaptured, so the log names the test.
if ! cargo test --no-fail-fast --all-features; then
status=1
cargo test --lib --all-features -- --test-threads=1 --nocapture || true
fi
cargo test --no-fail-fast --no-default-features || status=1
exit "$status"
EOS
su -l ci -c "sh /tmp/ci.sh '$RUST_TOOLCHAIN' '$PWD'"
container:
name: Container limits (cgroup v2)
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Build the container test
id: build
shell: bash
run: |
set -euo pipefail
exe=$(cargo test --test container --no-run --message-format=json \
| jq -r 'select(.executable != null and .target.name == "container") | .executable')
echo "exe=$exe" >> "$GITHUB_OUTPUT"
- name: Run it under --memory=256m --cpus=1.5 --cpuset-cpus=0-1
shell: bash
run: |
docker run --rm --memory=256m --cpus=1.5 --cpuset-cpus=0-1 \
-e SYS_LIB_EXPECT_MEMORY=268435456 -e SYS_LIB_EXPECT_CPUS=2 \
-v "${{ steps.build.outputs.exe }}:/test:ro" ubuntu:24.04 /test --nocapture
miri:
name: Miri (parsers and units)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@nightly
with:
components: miri
- uses: Swatinem/rust-cache@v2
- name: Miri
run: "cargo miri test --lib -- parse:: units:: fmt::"
env:
MIRIFLAGS: "-Zmiri-disable-isolation"
PROPTEST_CASES: "16"
nanoserver:
name: Nano Server
runs-on: windows-2022
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
- name: Build a static binary
env:
RUSTFLAGS: -Ctarget-feature=+crt-static
run: cargo build --example summary --features device-id
- name: Run it on Nano Server
shell: bash
run: |
mkdir nano && cp target/debug/examples/summary.exe nano/
docker run --rm -v "$(cygpath -w "$PWD/nano"):C:\\app" mcr.microsoft.com/windows/nanoserver:ltsc2022 'C:\app\summary.exe'
fuzz-smoke:
name: Fuzz (smoke, 20 s per target)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
with:
workspaces: fuzz
- name: Install cargo-fuzz
uses: taiki-e/install-action@v2
with:
tool: cargo-fuzz
- name: Run every target
shell: bash
run: |
set -euo pipefail
for target in $(cargo fuzz list); do
mkdir -p "$RUNNER_TEMP/corpus/$target"
cargo fuzz run --target x86_64-unknown-linux-gnu "$target" "$RUNNER_TEMP/corpus/$target" tests/fixtures -- -max_total_time=20
done
no-subprocess:
name: No subprocess at run time
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Only the build helper may start a program
shell: bash
run: |
set -euo pipefail
# 1. std::process::Command anywhere in src/ outside the build helper
# (src/build.rs, src/build/).
std_hits=$(grep -rnE 'Command::new|process::Command|process::\{[^}]*\bCommand\b' src --include='*.rs' \
| grep -vE '^src/build(\.rs|/)' || true)
# 2. Process-creation calls declared or called in the OS modules.
# Names followed by `(` (a declaration or a call), bare or through
# `ffi::` or `libc::`, so a method such as `Root::system()` does not
# match; comment lines are skipped so prose such as "a system call"
# does not either.
ffi_hits=$(grep -rnE '\b(CreateProcess(A|W|AsUserW)?|ShellExecute(Ex)?W|WinExec)\b|(^|[^:[:alnum:]_]|ffi::|libc::)(posix_spawnp?|execv[pe]?|execl[pe]?|popen|v?fork|system)[[:space:]]*\(' src/sys --include='*.rs' 2>/dev/null \
| grep -vE '^[^:]+:[0-9]+:[[:space:]]*//' || true)
if [ -n "$std_hits$ffi_hits" ]; then
echo "sys-lib never runs a program at run time (dev/PLAN.md, D-004)."
echo "$std_hits"
echo "$ffi_hits"
exit 1
fi
echo "No subprocess found outside the build helper."
package:
name: Package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Package
run: cargo package
security:
name: Security (audit + deny)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Install cargo-audit and cargo-deny
uses: taiki-e/install-action@v2
with:
tool: cargo-audit,cargo-deny
- name: Generate lockfile
run: cargo generate-lockfile
- name: Audit
run: cargo audit
- name: Deny
run: cargo deny check