|
| 1 | +--- |
| 2 | +title: "Rust Support" |
| 3 | +date: 2026-03-04 |
| 4 | +description: "DevRail now supports Rust -- clippy, rustfmt, cargo-audit, cargo-deny, and cargo test ship in the dev-toolchain container." |
| 5 | +--- |
| 6 | + |
| 7 | +Rust is the eighth language ecosystem in DevRail. Add `rust` to your `.devrail.yml` and the full toolchain is available immediately. |
| 8 | + |
| 9 | +## What Ships |
| 10 | + |
| 11 | +The dev-toolchain container includes the complete Rust toolchain and five tools: |
| 12 | + |
| 13 | +| Concern | Tool | What It Does | |
| 14 | +|---|---|---| |
| 15 | +| Linter | clippy | Official Rust linter, treats warnings as errors | |
| 16 | +| Formatter | rustfmt | Official Rust formatter | |
| 17 | +| Security | cargo-audit | Scans `Cargo.lock` against the RustSec Advisory Database | |
| 18 | +| Security | cargo-deny | Enforces license, ban, and source policies on dependencies | |
| 19 | +| Tests | cargo test | Built-in test runner, all targets | |
| 20 | + |
| 21 | +The entire Rust toolchain -- rustup, cargo, rustc, clippy, and rustfmt -- is COPY'd from the `rust:1-slim-bookworm` builder stage. Clippy and rustfmt are rustup components, tightly coupled to the compiler version. Shipping them together eliminates version drift between the linter, formatter, and compiler. |
| 22 | + |
| 23 | +cargo-audit and cargo-deny are installed via [cargo-binstall](https://github.com/cargo-bins/cargo-binstall) in the builder stage, avoiding long compilation times for these tools. |
| 24 | + |
| 25 | +## How It Works |
| 26 | + |
| 27 | +```yaml |
| 28 | +# .devrail.yml |
| 29 | +languages: |
| 30 | + - rust |
| 31 | +``` |
| 32 | +
|
| 33 | +```console |
| 34 | +$ make check |
| 35 | +✓ lint (cargo clippy --all-targets --all-features -- -D warnings) |
| 36 | +✓ format (cargo fmt --all -- --check) |
| 37 | +✓ security (cargo audit, cargo deny check) |
| 38 | +✓ test (cargo test --all-targets) |
| 39 | +✓ scan (trivy, gitleaks) |
| 40 | +``` |
| 41 | + |
| 42 | +`make fix` runs `cargo fmt --all` to auto-format in place. |
| 43 | + |
| 44 | +## Gating |
| 45 | + |
| 46 | +Each tool gates on the presence of the files it needs: |
| 47 | + |
| 48 | +- **clippy and rustfmt** gate on `*.rs` files |
| 49 | +- **cargo audit** gates on `Cargo.lock` -- skipped if no lock file exists |
| 50 | +- **cargo deny** gates on `deny.toml` -- skipped if no policy file exists |
| 51 | +- **cargo test** gates on `*.rs` files + `Cargo.toml` |
| 52 | + |
| 53 | +This means Rust tools run only when there is Rust code to check. A multi-language project that declares `rust` but has not yet added any `.rs` files will not fail. |
| 54 | + |
| 55 | +## Pre-Commit Hooks |
| 56 | + |
| 57 | +The template repositories include commented hooks using [pre-commit-cargo](https://github.com/AndrejOrsula/pre-commit-cargo): |
| 58 | + |
| 59 | +```yaml |
| 60 | +- repo: https://github.com/AndrejOrsula/pre-commit-cargo |
| 61 | + rev: v0.4.0 |
| 62 | + hooks: |
| 63 | + - id: cargo-fmt |
| 64 | + args: ["--all", "--", "--check"] |
| 65 | + - id: cargo-clippy |
| 66 | + args: ["--all-targets", "--all-features", "--workspace", "--", "-D", "warnings"] |
| 67 | +``` |
| 68 | +
|
| 69 | +Security scanning and tests remain CI-only due to execution time. |
| 70 | +
|
| 71 | +## Get Started |
| 72 | +
|
| 73 | +- [Rust standards reference](/docs/standards/rust/) -- configuration, Makefile targets, and notes |
| 74 | +- [Container tool versions](/docs/container/versions/) -- exact versions shipped in the current image |
0 commit comments