Skip to content

fix(host-config): dont apply target config to host artifacts #17123

Merged
ehuss merged 5 commits into
rust-lang:masterfrom
weihanglo:host-config-fix
Jun 20, 2026
Merged

fix(host-config): dont apply target config to host artifacts #17123
ehuss merged 5 commits into
rust-lang:masterfrom
weihanglo:host-config-fix

Conversation

@weihanglo

@weihanglo weihanglo commented Jun 20, 2026

Copy link
Copy Markdown
Member

What does this PR try to resolve?

With -Zhost-config,
a host artifact must only take its config from [host]
but never from [target.'cfg(...)'].

The bug is that the first branch of target_{linker,runner}
already routes [host] and [target] correctly.
However, later the cfg fallback read the global target_cfgs()
so a host artifact wrongly picked up the target's cfg() linker.

This patch follows the same pattern extra_args has used.

How to test and review this PR?

Two regression tests are added.

Fixes rust-lang/miri#5101

To test against the repro https://github.com/nazar-pc/miri-5101-reproduction, run

RUSTFLAGS="-Znext-solver=globally" MIRIFLAGS="-Znext-solver=globally" \
  rustup run nightly /path/to/pr17123/cargo miri test \
  -Ztarget-applies-to-host -Zhost-config \
  --config 'host.rustflags=["-Znext-solver=globally"]' --lib

With `-Zhost-config`,
a host artifact must only take its config from `[host]`
but never from `[target.'cfg(...)']`.

The first branch of `target_runner`
already routes `[host]` and `[target]` correctly.
However, later the cfg fallback read the global `target_cfgs()`
so a build script wrongly picked up the target's `cfg()` runner.

This patch follows the same pattern `extra_args` has used.
With `-Zhost-config`,
a host artifact must only take its config from `[host]`
but never from `[target.'cfg(...)']`.

The first branch of `target_linker`
already routes `[host]` and `[target]` correctly.
However, later the cfg fallback read the global `target_cfgs()`
so a host artifact wrongly picked up the target's `cfg()` linker.

This patch follows the same pattern `extra_args` has used.
@rustbot

rustbot commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

r? @epage

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

@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 Jun 20, 2026
@epage
epage added this pull request to the merge queue Jun 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 20, 2026
@ehuss
ehuss added this pull request to the merge queue Jun 20, 2026
Merged via the queue into rust-lang:master with commit a595d0d Jun 20, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 20, 2026
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Jun 20, 2026
Update cargo submodule

9 commits in 598ab48ec328e3e4f5e4e373d8df7264bc8e27cd..a595d0da21f228b7fdae64d3d5c0e527ea66bb59
2026-06-17 02:39:50 +0000 to 2026-06-20 13:42:59 +0000
- fix(host-config): dont apply target config to host artifacts  (rust-lang/cargo#17123)
- chore(deps): update msrv to v1.94 (rust-lang/cargo#17121)
- test(update): show cross-registry multi-spec precise (rust-lang/cargo#17119)
- fix(resolver): hint how to resolve too-new versions (rust-lang/cargo#17118)
- fix(add): list too-new versions and how to override (rust-lang/cargo#17117)
- feat: `-Zmin-publish-age` (RFC 3923) (rust-lang/cargo#17012)
- feat(diag): Support `build.warnings` for cargo lints (rust-lang/cargo#17112)
- Remove windows-sys dependencies older than 0.61 (rust-lang/cargo#17115)
- fix(install): Run cargo lints like rustc lints (rust-lang/cargo#17107)
@rustbot rustbot added this to the 1.98.0 milestone Jun 20, 2026
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Jun 21, 2026
Update cargo submodule

9 commits in 598ab48ec328e3e4f5e4e373d8df7264bc8e27cd..a595d0da21f228b7fdae64d3d5c0e527ea66bb59
2026-06-17 02:39:50 +0000 to 2026-06-20 13:42:59 +0000
- fix(host-config): dont apply target config to host artifacts  (rust-lang/cargo#17123)
- chore(deps): update msrv to v1.94 (rust-lang/cargo#17121)
- test(update): show cross-registry multi-spec precise (rust-lang/cargo#17119)
- fix(resolver): hint how to resolve too-new versions (rust-lang/cargo#17118)
- fix(add): list too-new versions and how to override (rust-lang/cargo#17117)
- feat: `-Zmin-publish-age` (RFC 3923) (rust-lang/cargo#17012)
- feat(diag): Support `build.warnings` for cargo lints (rust-lang/cargo#17112)
- Remove windows-sys dependencies older than 0.61 (rust-lang/cargo#17115)
- fix(install): Run cargo lints like rustc lints (rust-lang/cargo#17107)
@weihanglo
weihanglo deleted the host-config-fix branch June 22, 2026 14:45
weihanglo added a commit to weihanglo/cargo that referenced this pull request Jul 11, 2026
Captured behaviors are likely bugs introduced by rust-lang#17123

See also rust-lang/miri#5101
weihanglo added a commit to weihanglo/cargo that referenced this pull request Jul 11, 2026
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.
weihanglo added a commit to weihanglo/cargo that referenced this pull request Jul 11, 2026
Captured behaviors are likely bugs introduced by rust-lang#17123

See also rust-lang/miri#5101
weihanglo added a commit to weihanglo/cargo that referenced this pull request Jul 12, 2026
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.
pull Bot pushed a commit to Jankyboy/cargo that referenced this pull request Jul 13, 2026
### What does this PR try to resolve?

Related: rust-lang#17200

rust-lang#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-rust-lang#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 (rust-lang#17123) | this PR
(rust-lang#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 rust-lang#17200 for the runner/linker inconsistency they
document.

### Note

We'll need to backport this to 1.98-beta once it lands.
epage pushed a commit that referenced this pull request Jul 14, 2026
Captured behaviors are likely bugs introduced by #17123

See also rust-lang/miri#5101
epage pushed a commit that referenced this pull request Jul 14, 2026
#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.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-Zhost-config breaks cargo miri test on proc macros under Miri

4 participants