Skip to content

ci(deps): fail CI on unused Cargo dependencies - #130

Draft
siloteemu wants to merge 4 commits into
ROCm:mainfrom
siloteemu:ci/unused-dependency-check
Draft

siloteemu wants to merge 4 commits into
ROCm:mainfrom
siloteemu:ci/unused-dependency-check

Conversation

@siloteemu

Copy link
Copy Markdown

Motivation

  • Unused dependencies are still resolved, built and covered by dependency audits, and nothing in CI notices when one is added or left behind. Two had accumulated in the Linux desktop crate and two in the root workspace table. This PR removes them and adds a CI check so they do not come back; the earlier cleanup (fix(deps): drop unused crate dependencies #71) left that check for a separate change.

Technical Details

  • Removals. The Linux desktop crate (gui/linux) declared gio and glib 0.22, but no source file in it uses either, and the GTK crates it depends on use 0.20, so these two pulled in a second copy of both libraries. Removing them drops seven packages from gui/linux/Cargo.lock (gio, gio-sys, glib, glib-macros, glib-sys, gobject-sys, system-deps 9.0.0); the other entries only lose their version suffix, no remaining package changes version or checksum, and nothing is added. The unused axis-daemon and axis-pty entries are removed from the root [workspace.dependencies]; no member crate uses them, and the root Cargo.lock is unchanged.
  • CI check. One new step in the existing Clippy job installs cargo-shear 1.13.4 with --locked, then runs cargo shear --locked --deny-warnings for the root workspace and again for gui/linux, which is a separate Cargo workspace excluded from the root. It fails on an unused dependency, an unlinked source file, or a suppression that is no longer needed, and names the dependency as a GitHub annotation. There is no new job, so scripts/release_tools.py and scripts/verify_workflow_structure.py are unchanged, and the step is in a job that is already part of the publication gate. No permissions, actions, digests, or release, nightly or GUI jobs change.
  • Docs. DEVELOPMENT.md adds the two commands to the first block of Local Checks, explains how to suppress a false positive with a stated reason (ignored or ignored-paths under [package.metadata.cargo-shear] in the crate's Cargo.toml, or [workspace.metadata.cargo-shear] in the root Cargo.toml for a workspace entry), and mentions the check under CI/CD.
  • Why cargo-shear. cargo-machete checks only plain [dependencies], so an unused dev-, build- or platform-specific dependency passes, and its latest release does not compile on the pinned Rust 1.95.0. cargo-udeps needs nightly. rustc's unused_crate_dependencies lint is noisy per test target. cargo-shear checks every dependency section, sees code for every platform and optional feature, exits non-zero, and installs with --locked like the other pinned CI tools (cargo-audit, cargo-deny). 1.13.4 is the newest version that installs with --locked on 1.95.0.
  • Known limits. The check can miss a dependency that is declared twice (a workspace entry that no crate inherits because one crate pins its own copy, for example tokio-tungstenite) and one hidden by a module with the same name as the crate (windows in axis-pty). Both predate this change and are left for a follow-up.
  • Ask-first areas. Per AGENTS.md, edits to .github/workflows/ and to lockfiles are "ask first" areas. This PR edits both deliberately: the new CI step, and the removal of the seven packages from gui/linux/Cargo.lock. Please review those two with that in mind.

Security impact: none to the runtime or to enforcement. The desktop crate loses two unused direct dependencies and seven lockfile packages, so the dependency surface gets smaller. CI gains a check that only reads the repository and installs one pinned tool from crates.io with --locked.

Test Plan

Platforms: Linux aarch64 (Ubuntu-class host, Rust 1.95.0) for everything below; Windows and macOS through CI only.

  • cargo fmt --all -- --check, cargo fmt --manifest-path gui/linux/Cargo.toml -- --check, cargo clippy --locked --all-targets -- -D warnings, and cargo check --locked --workspace --all-targets.
  • cargo shear --locked --deny-warnings for the root workspace and for gui/linux, on this branch and on unmodified origin/main.
  • Negative tests in scratch copies: an unused dependency added to a crate; unused dev-, build- and macOS-only dependencies; code used only on Windows or only under an optional feature; a suppression with a reason; a stale suppression.
  • python3 scripts/verify_workflow_structure.py ., and cargo audit and cargo deny for gui/linux.
  • cargo test --locked, bash scripts/test_security_tier0.sh and python3 -m unittest discover -s scripts, compared against a pristine origin/main copy.

Test Result

  • Passed: all fmt checks; clippy; cargo check; cargo shear exits 0 on both workspaces on this branch. On origin/main it exits 1 for the root workspace, naming axis-daemon and axis-pty, and for gui/linux, naming gio and glib.
  • Negative tests: an unused dependency makes the check fail and names it; unused dev-, build- and macOS-only dependencies are flagged; code used only on Windows or only under an optional feature is not flagged; a suppression with a reason passes; a stale suppression fails.
  • Passed: scripts/verify_workflow_structure.py reports OK (with PyYAML installed); cargo audit and cargo deny pass for gui/linux.
  • Not verified, gui/linux build: it was not compiled, because the host has no GTK4 or WebKitGTK development libraries. The "Build Linux desktop" CI job is the only compile check of removing gio and glib.
  • Not verified, Windows and macOS: no builds were run, since cfg-gated code cannot be built on Linux. The only root change there is two unused workspace entries.
  • Not run: zizmor. Policy validation and the e2e scripts, because nothing under policies/ or the launch path changed.
  • Fail on this host, same as unmodified origin/main: cargo test --locked, scripts/test_security_tier0.sh and python3 -m unittest discover -s scripts, because the host has no trusted bwrap and filters seccomp-based tests. The failure sets are identical, so these tests give no signal for this change.
  • Unrelated: root cargo audit and cargo deny report RUSTSEC-2026-0592 on url, on origin/main too; the root Cargo.lock is unchanged here, and an open PR addresses it.
  • No signal: bash scripts/check_linux_mxc_packaging.sh exits 1 with no output on this host, both on this branch and on an unmodified origin/main copy. I did not find why, so it says nothing either way about this change.

The Linux desktop crate declared gio and glib 0.22, but no source file in it uses either. The GTK crates it depends on use gio and glib 0.20, so only this crate pulled in the 0.22 line and a second copy of both libraries and their -sys crates.

Remove the two dependencies. The crate's lockfile loses seven packages: gio, gio-sys, glib, glib-macros, glib-sys, gobject-sys and system-deps 9.0.0. With a single version of each left, the remaining entries drop their version suffixes.

Also remove the axis-daemon and axis-pty entries from the root [workspace.dependencies] table. No member crate inherits them, so they only add noise and would be reported by an unused-dependency check.

Signed-off-by: Teemu Kuusisto <[email protected]>
Unused dependencies had accumulated unnoticed, among them two in the Linux desktop crate and two workspace entries, because nothing in CI looks for them. They slow builds and widen the dependency surface that has to be audited.

Install a pinned cargo-shear in the existing Clippy job and fail when a dependency is unused in either Cargo workspace, the root one and gui/linux. cargo-shear is used rather than cargo-machete because it also checks dev, build and target-specific dependencies, and it works on the pinned toolchain.

Document the check in DEVELOPMENT.md, including the [package.metadata.cargo-shear] ignored list for a dependency used in a way the tool cannot see.

Signed-off-by: Teemu Kuusisto <[email protected]>
The cargo-shear step runs in the Clippy job on every PR, but the local checks
listed it only under dependency changes, so a source-only change could fail it
in CI without the contributor having run it. Move both invocations into the
block that applies to every change.

The suppression advice named only [package.metadata.cargo-shear], which does
not clear an unused entry in the root [workspace.dependencies] table. Name
both places, and the ignored-paths key for a source file that must stay
unlinked.

With --deny-warnings the check also fails on unlinked source files and on an
ignore entry that suppresses nothing, so say so in the documentation and in
the step name.

Signed-off-by: Teemu Kuusisto <[email protected]>
The local-checks paragraph about cargo-shear had grown into a block of
loosely related claims, several of them inaccurate when run against
cargo-shear 1.13.4:

- The CI/CD item said one command covers both Cargo workspaces. The root
  excludes gui/linux, so that command covers only the root; say that CI
  runs it once for each.
- "ignored-paths in the same table" did not say what the paths are relative
  to. They are relative to the crate in the package table and to the
  repository root in the workspace table, and a pattern written against the
  wrong one fails and adds a redundant-pattern warning.
- Only an ignore entry that matches nothing was named as a failure. Any
  cargo-shear warning fails under --deny-warnings, a suppression that is no
  longer needed included.
- A root [workspace.dependencies] entry is flagged when no member crate
  declares it by name, not when no crate inherits it.

Keep a one-line install note under the command block and move the
suppression guidance into its own short item. The sentence about GitHub
annotations for the gui/linux run is not a local check and is dropped.

Signed-off-by: Teemu Kuusisto <[email protected]>
@siloteemu
siloteemu force-pushed the ci/unused-dependency-check branch from 6ff8098 to fea0ebe Compare November 25, 2026 15:59

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant