Skip to content

fix(host-config): host.runner should not apply to cargo run#16638

Merged
epage merged 4 commits intorust-lang:masterfrom
weihanglo:host-runner
Feb 13, 2026
Merged

fix(host-config): host.runner should not apply to cargo run#16638
epage merged 4 commits intorust-lang:masterfrom
weihanglo:host-runner

Conversation

@weihanglo
Copy link
Member

What does this PR try to resolve?

host.runner was incorrectly applied to cargo run and other target
processes when -Zhost-config was enabled but no --target flag was
specified.

The root cause was that target_runner() used target_config(kind)
which routes through host_config for CompileKind::Host. But
CompileKind::Host is used for both build scripts and normal binaries
when no --target is specified.

Fixes #16634

How to test and review this PR?

Commit by commit.

Planned to change host.linker behavior though that "bug" has been there for years.
It is wiser to make a separate PR.

@rustbot
Copy link
Collaborator

rustbot commented Feb 13, 2026

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

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 13, 2026
@epage epage enabled auto-merge February 13, 2026 02:27
Add tests documenting that
`host.runner`incorrectly apply to normal target builds.

The test will be fixed in the next commit.
@epage epage added this pull request to the merge queue Feb 13, 2026
@weihanglo weihanglo removed this pull request from the merge queue due to a manual request Feb 13, 2026
.chain(Some(&CompileKind::Host))
.map(|kind| Ok((*kind, target_runner(bcx, *kind)?)))
.collect::<CargoResult<HashMap<_, _>>>()?;
if !bcx.gctx.target_applies_to_host()? {
Copy link
Member Author

Choose a reason for hiding this comment

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

The previous iteration was a premature fix because requested_kinds contains only CompileKind::Host when in non-cross-compilation mode. We need to insert target config with explicit target key here to ensure they are picked up.

See also the new tests in tool_paths.rs.

@weihanglo weihanglo force-pushed the host-runner branch 3 times, most recently from b0c8342 to 7e5b21f Compare February 13, 2026 07:12
host mode means without any `--target` cross-compilation settings
`host.runner` was incorrectly applied to `cargo run` and other target
processes when `-Zhost-config` was enabled but no `--target` flag was
specified.

The root cause was that `target_runner()` used `target_config(kind)`
which routes through `host_config` for `CompileKind::Host`. But
`CompileKind::Host` is used for both build scripts and normal binaries
when no `--target` is specified.
As it covers both host and target runners.
@epage epage added this pull request to the merge queue Feb 13, 2026
Merged via the queue into rust-lang:master with commit 312145c Feb 13, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 13, 2026
@weihanglo weihanglo deleted the host-runner branch February 13, 2026 22:19
github-merge-queue bot pushed a commit that referenced this pull request Feb 16, 2026
### What does this PR try to resolve?

Similar to <#16638>,
this prevents `host.linker` from applying to non-host build targets.

### How to test and review this PR?

This behavior has been there since the integration of host-config, so it
_might_ break somebody's assumption.

I've checked the use of `target_linker`:

* doctest continues using `target_linker` as it is more a target builds:
https://github.com/rust-lang/cargo/blob/312145c006c53906c7bd6c585e52f2639d37a191/src/cargo/core/compiler/build_runner/mod.rs?plain=1#L281-L289
* `RUSTC_LINKER` set for build scripts is on the same boat. It indicates
the linker to use for the associated crate, which is always a target
build:
https://github.com/rust-lang/cargo/blob/312145c006c53906c7bd6c585e52f2639d37a191/src/cargo/core/compiler/custom_build.rs?plain=1#L389-L391

Other than the two above, the other usages of it (fingerprint, and rustc
invocation) should respect host.linker when building build script
exectuables.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: CARGO_TARGET_<triple>_RUNNER used for build scripts

4 participants