Skip to content

rust-lint

cargo fmt --check + cargo clippy over the workspace, on the consolidated dev-tools image (rustup stable + clippy/rustfmt baked). A project's rust-toolchain.toml overrides the toolchain at runtime; rustup component add re-adds the components for an overridden toolchain.

Two jobs:

  • rustfmt — no target/ cache; rustfmt operates on source files only, and warming target/ with a debug build just to read it inflates the runner's disk budget.
  • clippy — carries the Cargo.lock-keyed target/ cache. Default flags --workspace --all-targets -- -D warnings; override features to switch between default-features and --all-features.

Change-detected by default. Consumers needing OS-level deps for an --all-features clippy run (e.g. libdbus-1-dev for a feature pulling libdbus-sys) extend extra_before_script.

Jobs

Job What it runs
rustfmt rustup component add rustfmt && cargo fmt --all --check
clippy rustup component add clippy && cargo clippy $[[ inputs.clippy_extra_args ]] $[[ inputs.features ]] -- -D warnings

Inputs

Input Type Default Description
image string dev-tools:v0.1.2 Rust toolchain image.
stage string lint GitLab CI stage.
if string '$CI_PIPELINE_SOURCE == "merge_request_event"' Gating rules:if: for both jobs.
changes array ["**/*.rs", "**/Cargo.toml", "Cargo.lock", "rustfmt.toml", "rust-toolchain.toml", ".gitlab-ci.yml"] Change-detection paths.
features string "--all-features" Feature flags for cargo clippy.
clippy_extra_args string "--workspace --all-targets" Extra arguments before -- -D warnings.
extra_before_script string "" Shell snippet prepended to each job's before_script (apt installs, env seeding).

Usage

include:
  - component: gitlab.com/phpboyscout/cicd/[email protected]

See also