Skip to content

experimental: add support for running clippy#445

Open
jrobsonchase wants to merge 6 commits intonix-community:masterfrom
jrobsonchase:clippy
Open

experimental: add support for running clippy#445
jrobsonchase wants to merge 6 commits intonix-community:masterfrom
jrobsonchase:clippy

Conversation

@jrobsonchase
Copy link
Contributor

@jrobsonchase jrobsonchase commented Mar 11, 2026

Closes #195

runClippy support

Add support for running clippy against a crate.

The user-facing API is similar to how runTests currently works. If runClippy = true in the call to buildRustCrateWithFeatures, an additional derivation is built that runs clippy against the root crate and is included in the "checks" (formerly "linked") derivation for the crate.

Overall approach

As suggested in #195, clippy is invoked by replacing rustc with (a script that runs) clippy-driver. This also has to do a bit of argument massaging to ensure that clippy is run without --cap-lints allow and to drop back to rustc if --version is provided, since apparently some build scripts like to call rustc --version and get mad if clippy responds.

The clever bit of this is that rustc is only replaced with clippy-driver in the root crate derivation, so all of its dependencies should be built with the originally-provided rustc and thus shouldn't need to be re-built for the clippy check. This is similar to how cargo-clippy works with the --no-deps argument.

Design notes

  • clippy must be included in the toolchain provided as the rustc input to buildRustCrate.
    • Might be worth adding an additional clippy argument to buildRustCrateWithFeatures? But then it feels "different" from how rustc and cargo are provided in the buildRustCrateForPkgs, which doesn't feel great. I think that clippy is also tightly coupled to rustc, so if there's a version mismatch, users could have a bad time.
  • Clippy is always run against the version of the crate derivation where runTests = true.
    • I'm not entirely sure if this also implies that clippy is run against the crate's binary/library target as well, or if passing --test makes clippy only run against the tests. Probably need to test some assumptions there. Assumptions tested - clippy does run against all targets, lib, bin, and integration test with the current setup.
    • Maybe we want another runClippyTests flag so that clippy can be run both against the main crate and the test crate? This is only useful if users specifically don't want clippy to run against tests, which seems puntable until someone specifically needs it for some reason.

Additional Changes

  • Refactored crateWithTests into a function that can support any number of arbitrary checks, not just the running of tests.
    • As a result, runCrateTests is now a standalone function that just constructs the "run the tests" derivation.
    • It also does the "Are there even any checks to include?" check, which was pushed down from buildRustCrateWithFeatures.
  • Pushed the buildTests = true attribute down into builtRustCratesWithFeatures where it was previously overridden in crateWithTests. I believe this is semantically equivalent.

TODO

  • Documentation
  • Tests

@jrobsonchase jrobsonchase marked this pull request as ready for review March 12, 2026 17:40
@jrobsonchase
Copy link
Contributor Author

Marking this ready for review while I work on tests and docs, since I think the core bits are ready for a look.

@jrobsonchase jrobsonchase force-pushed the clippy branch 2 times, most recently from 184436e to 9340746 Compare March 12, 2026 20:02
@jrobsonchase
Copy link
Contributor Author

@domenkozar Got tests and docs added, so this should be ready for review!

@jrobsonchase
Copy link
Contributor Author

Now with dogfooding of runTests and runClippy!

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.

How to run clippy in a check

1 participant