name: Rust
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
CARGO_TERM_COLOR: always
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Check formatting
run: cargo fmt --all --check
- name: Clippy
run: cargo clippy --all-targets -- -D warnings
msrv:
name: MSRV (1.75)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: "1.75"
- name: Check with MSRV
run: |
rm -f Cargo.lock
cargo check --lib
test:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: linux-x64
os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- name: linux-arm64
os: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
- name: macos-arm64
os: macos-latest
target: aarch64-apple-darwin
- name: windows-x64
os: windows-latest
target: x86_64-pc-windows-msvc
- name: windows-arm64
os: windows-11-arm
target: aarch64-pc-windows-msvc
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Test
run: cargo test --target ${{ matrix.target }}
- name: Run examples
shell: bash
run: |
set -euo pipefail
for example in singleflight rate_limiter lru_session_store; do
cargo run --example "$example" --target ${{ matrix.target }}
done
coverage:
name: Code Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@v2
with:
tool: cargo-llvm-cov
- name: Generate coverage report
run: cargo llvm-cov --all-features --workspace --cobertura --output-path cobertura.xml
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: SF-Zhou/lockmap
files: cobertura.xml
fail_ci_if_error: true
miri:
name: Miri Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Miri on nightly
uses: dtolnay/rust-toolchain@nightly
with:
components: miri
- name: Run Miri tests
run: cargo miri test --lib
tsan:
name: Thread Sanitizer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust nightly with rust-src
uses: dtolnay/rust-toolchain@nightly
with:
components: rust-src
- name: Run tests under ThreadSanitizer
run: cargo test --lib --release --target x86_64-unknown-linux-gnu -Zbuild-std
env:
RUSTFLAGS: -Zsanitizer=thread