Rust Support

DevRail now supports Rust – clippy, rustfmt, cargo-audit, cargo-deny, and cargo test ship in the dev-toolchain container.

Rust is the eighth language ecosystem in DevRail. Add rust to your .devrail.yml and the full toolchain is available immediately.

What Ships

The dev-toolchain container includes the complete Rust toolchain and five tools:

ConcernToolWhat It Does
LinterclippyOfficial Rust linter, treats warnings as errors
FormatterrustfmtOfficial Rust formatter
Securitycargo-auditScans Cargo.lock against the RustSec Advisory Database
Securitycargo-denyEnforces license, ban, and source policies on dependencies
Testscargo testBuilt-in test runner, all targets

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.

cargo-audit and cargo-deny are installed via cargo-binstall in the builder stage, avoiding long compilation times for these tools.

How It Works

# .devrail.yml
languages:
  - rust
$ make check
✓ lint       (cargo clippy --all-targets --all-features -- -D warnings)
✓ format     (cargo fmt --all -- --check)
✓ security   (cargo audit, cargo deny check)
✓ test       (cargo test --all-targets)
✓ scan       (trivy, gitleaks)

make fix runs cargo fmt --all to auto-format in place.

Gating

Each tool gates on the presence of the files it needs:

  • clippy and rustfmt gate on *.rs files
  • cargo audit gates on Cargo.lock – skipped if no lock file exists
  • cargo deny gates on deny.toml – skipped if no policy file exists
  • cargo test gates on *.rs files + Cargo.toml

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.

Pre-Commit Hooks

The template repositories include commented hooks using pre-commit-cargo:

- repo: https://github.com/AndrejOrsula/pre-commit-cargo
  rev: v0.4.0
  hooks:
    - id: cargo-fmt
      args: ["--all", "--", "--check"]
    - id: cargo-clippy
      args: ["--all-targets", "--all-features", "--workspace", "--", "-D", "warnings"]

Security scanning and tests remain CI-only due to execution time.

Get Started