Repository navigation
Rust: Systematically lint changed Rust code in CI - #23257
Conversation
2895105 to
0d036d7
Compare
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Setting SWIFT_SYNTAX_RS_CHECK_ONLY=1 skips the native Swift build, so cargo check and cargo clippy work without a Swift toolchain. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Replace the per-project Clippy steps with one workflow that lints only the root workspace packages affected by a change, including their reverse dependencies. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
0d036d7 to
5c5ff8c
Compare
There was a problem hiding this comment.
🟡 Changes recommended
After a force-push, an unavailable base commit causes the unchecked git diff to abort package selection before Clippy runs instead of conservatively selecting all packages.
1 open issue
What changed in this PR
Centralizes Rust linting in a Cargo-based workflow that selects affected root-workspace packages and their dependents, replacing scattered Clippy checks.
Changes:
- Adds package selection, selection tests, and cached Clippy runs for PRs and pushes.
- Removes redundant Clippy steps from existing workflows.
- Adds a Rust-only Swift shim check mode and resolves newly exposed Rust lint warnings.
| File | Description |
|---|---|
unified/swift-syntax-rs/README.md |
Documents Rust-only checks without building the native shim. |
unified/swift-syntax-rs/build.rs |
Adds an environment-controlled native build bypass. |
unified/extractor/src/languages/swift/swift.rs |
Renames bindings and simplifies optional-value handling for lint compliance. |
misc/scripts/cargo-clippy/test_cargo_clippy.py |
Tests package selection and dependency propagation. |
misc/scripts/cargo-clippy/cargo_clippy.py |
Selects affected workspace packages and invokes Clippy. |
.github/workflows/tree-sitter-extractor-test.yml |
Removes the separate Clippy job. |
.github/workflows/rust.yml |
Removes redundant Clippy steps. |
.github/workflows/cpp-bmn.yml |
Removes the local Clippy step. |
.github/workflows/cargo-clippy.yml |
Adds centralized selection, caching, source preparation, and linting. |
Review effort: Balanced (adaptive)
Select every workspace package when a push event's base commit is not available in the checkout. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Replacing CI lint gates affects repository-wide coverage through transitive package selection, generated-source handling, and Swift build bypasses, requiring substantive human review.
No open issues 🎉
1 resolved since last review
Review effort: Balanced (adaptive)
| @@ -0,0 +1,127 @@ | |||
| #!/usr/bin/env python3 | |||
There was a problem hiding this comment.
As far as I understand, the purpose of this file is to only run clippy across packages changed by the PR. How much speedup does that give? - I worry this adds unneeded additional complexity
There was a problem hiding this comment.
Yes, you understanding is correct. I'm not really pleased either that this requires such a big script but I couldn't find a simpler way.
The speedup depends a bit on which crates you measure. Linting only Unified takes 8.8 seconds on my machine vs 20 seconds for all crates.
Some arguments to this approach:
-
The additional workflows that run
clippydo so when their project changes, so I did this so the new approach would not be a performance regression. -
There's the important special case when no Rust projects have changed where we skip linting entirely. That's what makes it ok to run the check on every PR and avoids us having to restrict it to certain paths, which would be a long list of paths that we'd have to keep up to date when crates are added and dependencies change.
-
If we want to expand this action to also run
cargo fmtand/orcargo test, then the performance difference will be larger (especiallytestwhich requires a full build and actually running tests).
The last point also means that in the future this approach will let us remove more from the existing actions (all cargo invocations essentially) which makes the complexity a bit more justified.
There was a problem hiding this comment.
Linting only Unified takes 8.8 seconds on my machine vs 20 seconds for all crates.
20 seconds vs 8 seconds does not worry me, as there are plenty of other slower CI checks being run in parallel
There's the important special case when no Rust projects have changed
Could we not gate the CI check behind simple file globs on changes, e.g.
**/*.rs
**/Cargo.toml
etc.
If we want to expand this action to also run cargo fmt and/or cargo test
Fair point. Your call.
There was a problem hiding this comment.
Yeah, I somehow thought such general globs weren't supported. That would make the paths easier to maintain.
I still think I'm leaning towards keeping this mostly because it'll allow expanding to cargo test as well.
There was a problem hiding this comment.
For glob patterns supported, see the filter-pattern-cheat-sheet
I'm good either way. Up to you.
There was a problem hiding this comment.
Copilot mentioned that if there are tests that uses include_str!("../../...") to, e.g. load test fixtures, it would not be able to pick that up. I dont think we use that, so I'm not too worried about that if we in the future use the same script to run cargo test on changed crates.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
andersfugmann
left a comment
There was a problem hiding this comment.
Approved.
Note that the python script was reviewed with use of LLM's. I only skimmed it.
|
|
||
|
|
||
| # Run Clippy on the selected packages and return its exit code. | ||
| def lint(packages): |
There was a problem hiding this comment.
This selects only changed crates and their path dependents. That can resolve features differently from a full workspace run. If an unselected workspace crate enables a feature on a dependency shared with a selected crate, the full-workspace Clippy run could fail on the combined feature set while this check passes. I dont know if that is the case currently.
| @@ -0,0 +1,127 @@ | |||
| #!/usr/bin/env python3 | |||
There was a problem hiding this comment.
Copilot mentioned that if there are tests that uses include_str!("../../...") to, e.g. load test fixtures, it would not be able to pick that up. I dont think we use that, so I'm not too worried about that if we in the future use the same script to run cargo test on changed crates.

This PR adds a single action that lints all Rust code in the repo. Previously some specific actions had
cargo clippycommands and others didn't, so linting was ad-hoc and incomplete.The new action only lints Rust projects that are actually touched by a PR. It runs Clippy through Cargo. An alternative would have been to run Clippy through Bazel. I wasn't sure which approach was best, so I had Copilot try both. There's a sibling PR that does the same as this PR but through Bazel. My conclusion is:
cargo clippyis much faster. Here are the numbers from the experiments that Copilot ran. The numbers are from inserting a lint error in the Rust extractor:Single-run observations; job times exclude the separate selection job. Cached runs reused the same PR's cache.
Since Cargo is much faster, I went with that approach. No need to waste Action minutes. I've only lightly skimmed over the
cargo_clippy.pyscript.