Skip to content

fix: dont apply host-config gating to stable behavior#17198

Merged
epage merged 3 commits into
rust-lang:masterfrom
weihanglo:host-linker
Jul 13, 2026
Merged

fix: dont apply host-config gating to stable behavior#17198
epage merged 3 commits into
rust-lang:masterfrom
weihanglo:host-linker

Conversation

@weihanglo

@weihanglo weihanglo commented Jul 11, 2026

Copy link
Copy Markdown
Member

What does this PR try to resolve?

Related: #17200

#17123 made host artifacts stop picking up
target.cfg(…).runner and target.cfg(…).linker
even without -Zhost-config.
That silently changed stable behavior that
target.cfg no longer applied to proc-macro
and build script compilation under --target <host>,
while target.<triple> config still did.

The old gate reused host_artifact_uses_only_host_config,
which is for the documented rustflags dual behavior.
It wasn't for runner and linker.

This PR narrows the gate to target-applies-to-host = false
and restore to pre-#17123 stable behavior,
while keeping -Zhost-config fix as it is still nightly.

How to test and review this PR?

I've added a lot of tests because I don't want to miss any edge cases again.

Here is the change table.

test 1.97 1.98-beta (#17123) this PR (#17198)
custom_runner_cfg_proc_macro_test_with_target applies not applies
target_cfg_linker_build_script_with_target applies not applies
target_cfg_linker_proc_macro_with_target applies not applies
target_cfg_linker_proc_macro_test_with_target applies not applies
target_cfg_runner_build_script_with_host_config_and_target applies not not
target_cfg_linker_build_script_with_host_config_and_target applies not not

All other added tests behave identically across 1.97, 1.98-beta, and this PR.
See #17200 for the runner/linker inconsistency they document.

Note

We'll need to backport this to 1.98-beta once it lands.

Captured behaviors are likely bugs introduced by rust-lang#17123

See also rust-lang/miri#5101
@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-cfg-expr Area: Platform cfg expressions S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 11, 2026
@rustbot

rustbot commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

r? @ehuss

rustbot has assigned @ehuss.
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

@RalfJung

RalfJung commented Jul 11, 2026

Copy link
Copy Markdown
Member

This means we'll have to revert rust-lang/miri@afd5aff in Miri, so please let me know when this lands in the main repo. Maybe we can even include the revert of that commit in the PR that syncs this update to rust-lang/rust?


What is the intended behavior of target.runner wrt proc macro tests in various flag configurations after this PR?

  • IMO it should never apply since proc macro tests clearly are a host artifact. Even cargo agrees with that: cargo passes --target to rustc for target artifacts, but does not pass --target to proc macro tests. So IMO with this PR cargo becomes internally inconsistent, where proc macro tests are the only kinds of crates that get built without --target but they get run with target.runner. That's why Miri needs special hacks to work around this inconsistency.
  • I could live with it always applying target.runner. We'll just have to keep our special hack in Miri then.
  • But if it gets sometimes applied and sometimes not (depending on -Z flags or so), then Miri is screwed. (Well maybe there's something complicated we can do depending on the exact circumstances of what this looks like. But it sure won't be pretty.)

.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
.with_stderr_data(str![[r#"
...
[RUNNING] `[ROOT]/foo/target/debug/deps/foo-[HASH][EXE]`

@RalfJung RalfJung Jul 11, 2026

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.

Am I misunderstanding this test, or does this not use any of the runners? That seems very strange?

View changes since the review

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.

No, your are not. This is likely a bug.

What is the intended behavior of target.runner wrt proc macro tests in various flag configurations after this PR?

Some purposes of this PR are

  • to revert some stable behavior back to whatever 1.97 has, in order to give us a room to breath and discuss the intended behavior
  • to capture the current state of the interaction around proc macro (tests)

See the counterpart PR against 1.97 that has the same issue https://github.com/weihanglo/cargo/pull/92/changes.

I am sorry about the whole mess. Will try to follow up with a new Cargo issue.

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.

Some purposes of this PR are

That makes sense to me, thanks.

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.

Opened #17200.


This means we'll have to revert rust-lang/miri@afd5aff in Miri, so please let me know when this lands in the main repo. Maybe we can even include the revert of that commit in the PR that syncs this update to rust-lang/rust?

Regarding this, I think we will backport this to 1.98-beta. Will kindly ask for your help to also revert that in beta when Cargo's beta backport PR merges. I am willing to do the Cargo submodule/ Miri subtree sync for both beta and nightly 🙇🏾‍♂️

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.

Miri is nightly-only so beta backports don't affect us.

rust-lang#17123 made host artifacts stop picking up
`target.'cfg(..)'.runner` and `target.'cfg(..)'.linker`
even without `-Ztarget-applies-to-host -Zhost-config`.
That silently changed stable behavior that
`target.'cfg(..)'` no longer applied to proc-macro
and build script compilation under `--target <host>`,
while `target.<triple>` config still did.

The old gate reused `host_artifact_uses_only_host_config`,
which is for the documented rustflags dual behavior.
It wasn't for runner and linker.

This PR narrows the gate to `target-applies-to-host = false`
and restore to pre PR 17123 stable behavior,
while keeping `-Zhost-config` fix as it is still nightly.
@epage
epage added this pull request to the merge queue Jul 13, 2026
Merged via the queue into rust-lang:master with commit 877ff64 Jul 13, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 13, 2026
@weihanglo
weihanglo deleted the host-linker branch July 13, 2026 22:01
epage added a commit that referenced this pull request Jul 14, 2026
Beta backports

- #17198

In order to make CI pass, the following PRs are also cherry-picked:

-
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Jul 18, 2026
Update cargo submodule

29 commits in 59800466c5c41c444d264b1010b4d57e85a7117f..3efb1f477e99b42974b982d939fd100303cdf7db
2026-07-07 15:52:22 +0000 to 2026-07-17 23:53:19 +0000
- refactor(context): normalize in `homedir` instead (rust-lang/cargo#17222)
- chore(ci): reflect doc folder move in book deployment (rust-lang/cargo#17235)
- refactor(ops): Have cargo-metadata's ops match the command name (rust-lang/cargo#17233)
- chore: Flatten src (rust-lang/cargo#17231)
- chore: Flatten `src` (rust-lang/cargo#17230)
- chore(ci): remove stale libsecret packages (rust-lang/cargo#17229)
- perf: Lazily initialize git2 fetch transports  (rust-lang/cargo#17226)
- test(trim-paths): re-enable lldb debugger tests  (rust-lang/cargo#17223)
- Include SBOM outputs in fingerprints (rust-lang/cargo#17216)
- Update cfg_aliases to 0.2.2 (rust-lang/cargo#17225)
- test(trim-paths): exercise GDB on windows-gnu (rust-lang/cargo#17221)
- feat(profile): Disable incremental compilation under CI by default (rust-lang/cargo#17220)
- Remove myself from review rotation (rust-lang/cargo#17219)
- Fix typo in comment in sync (rust-lang/cargo#17217)
- docs(ref): Improve handing of built-in profiles (rust-lang/cargo#17213)
- fix: dont apply host-config gating to stable behavior (rust-lang/cargo#17198)
- chore(deps): update msrv (rust-lang/cargo#17192)
- test: fix race in cargo_compile_with_invalid_code_in_deps (rust-lang/cargo#17203)
- Rename `-Zno-embed-metadata` to `-Zembed-metadata=no` (rust-lang/cargo#17149)
- fix(source): incorrect duplicate package warning (rust-lang/cargo#17204)
- Fix manifest schema generation: `TomlDebugInfo` enum-variants doesn't renamed (rust-lang/cargo#17202)
- Reduce library search path length in new build dir layout (rust-lang/cargo#17191)
- fix(install): Move --debug to Compilation options (rust-lang/cargo#17199)
- chore(ci): dogfood `build.warnings` (rust-lang/cargo#17195)
- docs(lints): Better match clippy in lint section titles (rust-lang/cargo#17190)
- chore: bump to 0.100.0; update changelog (rust-lang/cargo#17189)
- docs(ref): Clarify MSRV for lints (rust-lang/cargo#17184)
- docs(report): add missing entry for `cargo report future-incompatibilities` (rust-lang/cargo#17188)
- Reduce rustc `-L` args used in the new `build-dir` layout (rust-lang/cargo#17168)
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Jul 18, 2026
Update cargo submodule

29 commits in 59800466c5c41c444d264b1010b4d57e85a7117f..3efb1f477e99b42974b982d939fd100303cdf7db
2026-07-07 15:52:22 +0000 to 2026-07-17 23:53:19 +0000
- refactor(context): normalize in `homedir` instead (rust-lang/cargo#17222)
- chore(ci): reflect doc folder move in book deployment (rust-lang/cargo#17235)
- refactor(ops): Have cargo-metadata's ops match the command name (rust-lang/cargo#17233)
- chore: Flatten src (rust-lang/cargo#17231)
- chore: Flatten `src` (rust-lang/cargo#17230)
- chore(ci): remove stale libsecret packages (rust-lang/cargo#17229)
- perf: Lazily initialize git2 fetch transports  (rust-lang/cargo#17226)
- test(trim-paths): re-enable lldb debugger tests  (rust-lang/cargo#17223)
- Include SBOM outputs in fingerprints (rust-lang/cargo#17216)
- Update cfg_aliases to 0.2.2 (rust-lang/cargo#17225)
- test(trim-paths): exercise GDB on windows-gnu (rust-lang/cargo#17221)
- feat(profile): Disable incremental compilation under CI by default (rust-lang/cargo#17220)
- Remove myself from review rotation (rust-lang/cargo#17219)
- Fix typo in comment in sync (rust-lang/cargo#17217)
- docs(ref): Improve handing of built-in profiles (rust-lang/cargo#17213)
- fix: dont apply host-config gating to stable behavior (rust-lang/cargo#17198)
- chore(deps): update msrv (rust-lang/cargo#17192)
- test: fix race in cargo_compile_with_invalid_code_in_deps (rust-lang/cargo#17203)
- Rename `-Zno-embed-metadata` to `-Zembed-metadata=no` (rust-lang/cargo#17149)
- fix(source): incorrect duplicate package warning (rust-lang/cargo#17204)
- Fix manifest schema generation: `TomlDebugInfo` enum-variants doesn't renamed (rust-lang/cargo#17202)
- Reduce library search path length in new build dir layout (rust-lang/cargo#17191)
- fix(install): Move --debug to Compilation options (rust-lang/cargo#17199)
- chore(ci): dogfood `build.warnings` (rust-lang/cargo#17195)
- docs(lints): Better match clippy in lint section titles (rust-lang/cargo#17190)
- chore: bump to 0.100.0; update changelog (rust-lang/cargo#17189)
- docs(ref): Clarify MSRV for lints (rust-lang/cargo#17184)
- docs(report): add missing entry for `cargo report future-incompatibilities` (rust-lang/cargo#17188)
- Reduce rustc `-L` args used in the new `build-dir` layout (rust-lang/cargo#17168)
@rustbot rustbot added this to the 1.99.0 milestone Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-build-execution Area: anything dealing with executing the compiler A-cfg-expr Area: Platform cfg expressions beta-nominated Nominated to backport to the beta branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants