Skip to content

fix(clean): respect build.target config for clean -p#16988

Merged
weihanglo merged 3 commits into
rust-lang:masterfrom
0xPoe:poe-patch-clean
May 13, 2026
Merged

fix(clean): respect build.target config for clean -p#16988
weihanglo merged 3 commits into
rust-lang:masterfrom
0xPoe:poe-patch-clean

Conversation

@0xPoe

@0xPoe 0xPoe commented May 11, 2026

Copy link
Copy Markdown
Member

What does this PR try to resolve?

Fixes #16974.

cargo clean -p ignored build.target config. clean_specs resolves requested_kinds with the config fallback, but the layout selection rechecked the raw CLI targets vec instead. Switched to checking target_layouts.is_empty().

How should we test and review this PR?

Two commits: a test capturing the buggy Summary 0 files output, then a one-line fix that flips the test expectation.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 11, 2026
@rustbot

rustbot commented May 11, 2026

Copy link
Copy Markdown
Collaborator

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage, weihanglo

@0xPoe 0xPoe marked this pull request as draft May 11, 2026 19:11
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 11, 2026
@0xPoe 0xPoe force-pushed the poe-patch-clean branch from 49db6cb to 0505b03 Compare May 11, 2026 19:25
@0xPoe 0xPoe marked this pull request as ready for review May 11, 2026 19:26
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 11, 2026
0xPoe added 3 commits May 11, 2026 21:43
Captures the current behavior where `cargo clean -p <pkg>` ignores the
`build.target` config and reports 0 files, even though the build produced
target-specific artifacts. See rust-lang#16974.
`clean_specs` resolves the requested kinds via `from_requested_targets`,
which already falls back to `build.target` when no `--target` is passed.
However, the layout selection then re-checked the raw CLI `targets` vec
and dropped down to the host layout whenever `--target` was absent,
ignoring the config fallback.

Switch the check to `target_layouts.is_empty()` so a config-only target
selects the target layouts, matching `--target` and the behavior
documented for `cargo clean`.

Fixes rust-lang#16974
@0xPoe 0xPoe force-pushed the poe-patch-clean branch from 0505b03 to 1c2b328 Compare May 11, 2026 19:44

@0xPoe 0xPoe left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🔢 Self-check (PR reviewed by myself and ready for feedback)

  • Code compiles successfully

  • Unit tests added

  • No AI-generated elegant nonsense in PR.

  • Comments added where necessary

  • PR title and description updated

  • Documentation PR created (or confirmed not needed)

  • PR size is reasonable

View changes since this review

@weihanglo weihanglo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a reasonable fix, though it is changing the behavior of cargo clean with a slightly hard-to-notice way that people may not even realize they have configured build.target in the Cargo configuration file. We should probably put this under Cargo's own compatibility notice in Changelog

Thanks for the fix anyway.

View changes since this review

@weihanglo weihanglo added this pull request to the merge queue May 13, 2026
Merged via the queue into rust-lang:master with commit 9a624d6 May 13, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 13, 2026
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request May 16, 2026
Update cargo submodule

7 commits in a343accce8526b128adc517d33348573d22920a3..4d1f984518c77fad6eeef4f40153b002a659e662
2026-05-08 22:41:35 +0000 to 2026-05-15 17:12:01 +0000
- Revert "feat: add frame-pointers profile option (rust-lang/cargo#16742)" (rust-lang/cargo#16999)
- CI: update to macos-15 (rust-lang/cargo#16996)
- fix(clean): respect `build.target` config for `clean -p` (rust-lang/cargo#16988)
- fix(diag): Consolidate verify/run diagnostics passes  (rust-lang/cargo#16989)
- fix(diag): Track Cargo diagnostic warning/error count like is done for rustc (rust-lang/cargo#16981)
- fix: suggest 'fmt' when user types 'cargo rustfmt' (rust-lang/cargo#16985)
- Rebuild when -Zpublic-dependency changes (rust-lang/cargo#16965)

r? ghost
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request May 16, 2026
Update cargo submodule

7 commits in a343accce8526b128adc517d33348573d22920a3..4d1f984518c77fad6eeef4f40153b002a659e662
2026-05-08 22:41:35 +0000 to 2026-05-15 17:12:01 +0000
- Revert "feat: add frame-pointers profile option (rust-lang/cargo#16742)" (rust-lang/cargo#16999)
- CI: update to macos-15 (rust-lang/cargo#16996)
- fix(clean): respect `build.target` config for `clean -p` (rust-lang/cargo#16988)
- fix(diag): Consolidate verify/run diagnostics passes  (rust-lang/cargo#16989)
- fix(diag): Track Cargo diagnostic warning/error count like is done for rustc (rust-lang/cargo#16981)
- fix: suggest 'fmt' when user types 'cargo rustfmt' (rust-lang/cargo#16985)
- Rebuild when -Zpublic-dependency changes (rust-lang/cargo#16965)

r? ghost
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request May 17, 2026
Update cargo submodule

7 commits in a343accce8526b128adc517d33348573d22920a3..4d1f984518c77fad6eeef4f40153b002a659e662
2026-05-08 22:41:35 +0000 to 2026-05-15 17:12:01 +0000
- Revert "feat: add frame-pointers profile option (rust-lang/cargo#16742)" (rust-lang/cargo#16999)
- CI: update to macos-15 (rust-lang/cargo#16996)
- fix(clean): respect `build.target` config for `clean -p` (rust-lang/cargo#16988)
- fix(diag): Consolidate verify/run diagnostics passes  (rust-lang/cargo#16989)
- fix(diag): Track Cargo diagnostic warning/error count like is done for rustc (rust-lang/cargo#16981)
- fix: suggest 'fmt' when user types 'cargo rustfmt' (rust-lang/cargo#16985)
- Rebuild when -Zpublic-dependency changes (rust-lang/cargo#16965)

r? ghost
@rustbot rustbot added this to the 1.97.0 milestone May 17, 2026
pull Bot pushed a commit to Kokoro2336/rust-analyzer that referenced this pull request May 17, 2026
Update cargo submodule

7 commits in a343accce8526b128adc517d33348573d22920a3..4d1f984518c77fad6eeef4f40153b002a659e662
2026-05-08 22:41:35 +0000 to 2026-05-15 17:12:01 +0000
- Revert "feat: add frame-pointers profile option (rust-lang/cargo#16742)" (rust-lang/cargo#16999)
- CI: update to macos-15 (rust-lang/cargo#16996)
- fix(clean): respect `build.target` config for `clean -p` (rust-lang/cargo#16988)
- fix(diag): Consolidate verify/run diagnostics passes  (rust-lang/cargo#16989)
- fix(diag): Track Cargo diagnostic warning/error count like is done for rustc (rust-lang/cargo#16981)
- fix: suggest 'fmt' when user types 'cargo rustfmt' (rust-lang/cargo#16985)
- Rebuild when -Zpublic-dependency changes (rust-lang/cargo#16965)

r? ghost
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request May 20, 2026
Update cargo submodule

7 commits in a343accce8526b128adc517d33348573d22920a3..4d1f984518c77fad6eeef4f40153b002a659e662
2026-05-08 22:41:35 +0000 to 2026-05-15 17:12:01 +0000
- Revert "feat: add frame-pointers profile option (rust-lang/cargo#16742)" (rust-lang/cargo#16999)
- CI: update to macos-15 (rust-lang/cargo#16996)
- fix(clean): respect `build.target` config for `clean -p` (rust-lang/cargo#16988)
- fix(diag): Consolidate verify/run diagnostics passes  (rust-lang/cargo#16989)
- fix(diag): Track Cargo diagnostic warning/error count like is done for rustc (rust-lang/cargo#16981)
- fix: suggest 'fmt' when user types 'cargo rustfmt' (rust-lang/cargo#16985)
- Rebuild when -Zpublic-dependency changes (rust-lang/cargo#16965)

r? ghost
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.

clean -p ignores build.target config when selecting target-specific artifacts

3 participants