Skip to content

Rust: Lint affected Cargo workspace packages in CI - #23257

Draft
paldepind wants to merge 3 commits into
mainfrom
paldepind-cargo-clippy-ci
Draft

paldepind wants to merge 3 commits into
mainfrom
paldepind-cargo-clippy-ci

Conversation

@paldepind

@paldepind paldepind commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds a single action that lints all Rust code in the repo. Previously some specific actions had cargo clippy commands 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:

  1. the overall complexity of the setup is around the same, no clear win there.
  2. using cargo clippy is much faster. Here are the numbers from the experiments that Copilot ran. The numbers are from inserting a lint error in the Rust extractor:
Cargo Bazel
Deliberate error, extractor only, no cache 67s 5m15s
Deliberate error, all targets, cached 48s 2m07s
Clean, all targets, no cache 92s 8m31s
Clean, all targets, cached 51–64s 2m31–2m51s

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.py script.

Aly589624

This comment was marked as spam.

paldepind and others added 3 commits November 27, 2026 10:27
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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)

Comment on lines +92 to +95
return subprocess.check_output(
["git", "diff", "--name-only", "--no-renames", "-z", base, "HEAD"],
cwd=root,
).decode().split("\0")

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants