Rust CI Setup
Configure a complete CI pipeline for a Rust project.
When to Use
- New Rust project needs CI from scratch
- Adding quality gates (fmt, clippy, test, audit) to an existing project
- Setting up advanced validation (Miri, sanitizers, fuzzing)
- Migrating CI to a new provider
Pipeline Layers
Layer 1: Fast Feedback (every PR)
| Step |
Command |
Purpose |
| Format |
cargo fmt --all -- --check |
Style consistency |
| Lint |
cargo clippy --workspace --all-targets --all-features -- -D warnings |
Code quality |
| Test |
cargo nextest run --workspace --all-features (or cargo test) |
Correctness |
| Doc |
cargo doc --workspace --all-features --no-deps |
Documentation builds |
Layer 2: Security & Dependencies (every PR or scheduled)
| Step |
Command |
Purpose |
| Audit |
cargo audit |
Known vulnerabilities |
| Deny |
cargo deny check |
Licenses, bans, duplicates, advisories |
| MSRV |
cargo hack check --rust-version --workspace |
Minimum supported version |
Layer 3: Deep Validation (nightly/scheduled)
| Step |
Command |
Purpose |
| Miri |
cargo +nightly miri test |
Undefined behavior detection |
| Sanitizers |
RUSTFLAGS="-Zsanitizer=address" |
Memory errors |
| Fuzzing |
cargo fuzz run <target> -- -max_total_time=300 |
Input space exploration |
| Coverage |
cargo llvm-cov --workspace --all-features --lcov --output-path lcov.info |
Code coverage |
GitHub Actions Baseline
name: ci
on:
push:
branches: [main]
pull_request:
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-Dwarnings"
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache Cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Format
run: cargo fmt --all -- --check
- name: Clippy
run: cargo clippy --workspace --all-targets --all-features
- name: Test
run: cargo test --workspace --all-features
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Install cargo-deny
uses: taiki-e/install-action@cargo-deny
- name: Install cargo-audit
uses: taiki-e/install-action@cargo-audit
- run: cargo audit
- run: cargo deny check
miri:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
components: miri
- run: cargo +nightly miri test --workspace
Configuration Files
rustfmt.toml
style_edition = "2024"
clippy.toml
msrv = "1.85"
deny.toml
[advisories]
vulnerability = "deny"
unmaintained = "warn"
yanked = "warn"
[licenses]
allow = ["MIT", "Apache-2.0", "BSD-2-Clause", "BSD-3-Clause", "ISC", "Unicode-3.0"]
[bans]
multiple-versions = "warn"
wildcards = "deny"
[sources]
unknown-registry = "deny"
unknown-git = "deny"
Cargo.toml metadata
[package]
edition = "2024"
rust-version = "1.85"
[lints.clippy]
all = "warn"
pedantic = "warn"
Process
- Determine project type (library, binary, workspace).
- Start with Layer 1 for every PR.
- Add Layer 2 for security-conscious projects.
- Add Layer 3 as scheduled jobs for projects with unsafe code, parsers, or FFI.
- Configure caching for
~/.cargo/registry, ~/.cargo/git, and target.
- Set MSRV in
Cargo.toml and verify in CI.
- Commit
Cargo.lock (recommended as starting point for all projects).
Tooling Installation
For CI, prefer taiki-e/install-action for fast binary installs:
cargo-nextest, cargo-deny, cargo-audit, cargo-llvm-cov, cargo-hack
For local development:
cargo install cargo-nextest cargo-deny cargo-audit cargo-llvm-cov cargo-hack
rustup component add rustfmt clippy
Source: woliveiras/geremmyas — distributed by TomeVault.
1---2name: woliveiras-geremmyas-rust-ci-setup3description: Rust CI Setup4---56# Rust CI Setup78Configure a complete CI pipeline for a Rust project.910## When to Use1112- New Rust project needs CI from scratch13- Adding quality gates (fmt, clippy, test, audit) to an existing project14- Setting up advanced validation (Miri, sanitizers, fuzzing)15- Migrating CI to a new provider1617## Pipeline Layers1819### Layer 1: Fast Feedback (every PR)2021| Step | Command | Purpose |22|------|---------|---------|23| Format | `cargo fmt --all -- --check` | Style consistency |24| Lint | `cargo clippy --workspace --all-targets --all-features -- -D warnings` | Code quality |25| Test | `cargo nextest run --workspace --all-features` (or `cargo test`) | Correctness |26| Doc | `cargo doc --workspace --all-features --no-deps` | Documentation builds |2728### Layer 2: Security & Dependencies (every PR or scheduled)2930| Step | Command | Purpose |31|------|---------|---------|32| Audit | `cargo audit` | Known vulnerabilities |33| Deny | `cargo deny check` | Licenses, bans, duplicates, advisories |34| MSRV | `cargo hack check --rust-version --workspace` | Minimum supported version |3536### Layer 3: Deep Validation (nightly/scheduled)3738| Step | Command | Purpose |39|------|---------|---------|40| Miri | `cargo +nightly miri test` | Undefined behavior detection |41| Sanitizers | `RUSTFLAGS="-Zsanitizer=address"` | Memory errors |42| Fuzzing | `cargo fuzz run <target> -- -max_total_time=300` | Input space exploration |43| Coverage | `cargo llvm-cov --workspace --all-features --lcov --output-path lcov.info` | Code coverage |4445## GitHub Actions Baseline4647```yaml48name: ci4950on:51 push:52 branches: [main]53 pull_request:5455env:56 CARGO_TERM_COLOR: always57 RUSTFLAGS: "-Dwarnings"5859jobs:60 check:61 runs-on: ubuntu-latest62 steps:63 - uses: actions/checkout@v46465 - name: Install Rust toolchain66 uses: dtolnay/rust-toolchain@stable67 with:68 components: rustfmt, clippy6970 - name: Cache Cargo71 uses: actions/cache@v472 with:73 path: |74 ~/.cargo/registry75 ~/.cargo/git76 target77 key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}78 restore-keys: ${{ runner.os }}-cargo-7980 - name: Format81 run: cargo fmt --all -- --check8283 - name: Clippy84 run: cargo clippy --workspace --all-targets --all-features8586 - name: Test87 run: cargo test --workspace --all-features8889 security:90 runs-on: ubuntu-latest91 steps:92 - uses: actions/checkout@v493 - uses: dtolnay/rust-toolchain@stable94 - name: Install cargo-deny95 uses: taiki-e/install-action@cargo-deny96 - name: Install cargo-audit97 uses: taiki-e/install-action@cargo-audit98 - run: cargo audit99 - run: cargo deny check100101 miri:102 runs-on: ubuntu-latest103 if: github.event_name == 'push' && github.ref == 'refs/heads/main'104 steps:105 - uses: actions/checkout@v4106 - uses: dtolnay/rust-toolchain@nightly107 with:108 components: miri109 - run: cargo +nightly miri test --workspace110```111112## Configuration Files113114### `rustfmt.toml`115116```toml117style_edition = "2024"118```119120### `clippy.toml`121122```toml123msrv = "1.85"124```125126### `deny.toml`127128```toml129[advisories]130vulnerability = "deny"131unmaintained = "warn"132yanked = "warn"133134[licenses]135allow = ["MIT", "Apache-2.0", "BSD-2-Clause", "BSD-3-Clause", "ISC", "Unicode-3.0"]136137[bans]138multiple-versions = "warn"139wildcards = "deny"140141[sources]142unknown-registry = "deny"143unknown-git = "deny"144```145146### `Cargo.toml` metadata147148```toml149[package]150edition = "2024"151rust-version = "1.85"152153[lints.clippy]154all = "warn"155pedantic = "warn"156```157158## Process1591601. Determine project type (library, binary, workspace).1612. Start with Layer 1 for every PR.1623. Add Layer 2 for security-conscious projects.1634. Add Layer 3 as scheduled jobs for projects with unsafe code, parsers, or FFI.1645. Configure caching for `~/.cargo/registry`, `~/.cargo/git`, and `target`.1656. Set MSRV in `Cargo.toml` and verify in CI.1667. Commit `Cargo.lock` (recommended as starting point for all projects).167168## Tooling Installation169170For CI, prefer `taiki-e/install-action` for fast binary installs:171- `cargo-nextest`, `cargo-deny`, `cargo-audit`, `cargo-llvm-cov`, `cargo-hack`172173For local development:174```bash175cargo install cargo-nextest cargo-deny cargo-audit cargo-llvm-cov cargo-hack176rustup component add rustfmt clippy177```178179---180> Source: [woliveiras/geremmyas](https://github.com/woliveiras/geremmyas) — distributed by [TomeVault](https://tomevault.io).181<!-- tomevault:4.0:skill_md:2026-06-16 -->