Skip to content

Add host.runner for wrapping host build target executions#16599

Merged
weihanglo merged 1 commit intorust-lang:masterfrom
tangramdotdev:host-runner
Feb 9, 2026
Merged

Add host.runner for wrapping host build target executions#16599
weihanglo merged 1 commit intorust-lang:masterfrom
tangramdotdev:host-runner

Conversation

@nitsky
Copy link
Contributor

@nitsky nitsky commented Feb 6, 2026

What does this PR try to resolve?

This PR resolves #16591 by adding support for host.runner config under the existing -Zhost-config unstable feature. Cargo already has target.<triple>.runner to wrap execution of target binaries (cargo run/test/bench), but no equivalent for host build targets like build scripts.

How to test and review this PR?

The implementation is two small changes in compilation.rs:

  1. target_runner() now uses bcx.target_data.target_config(kind).runner instead of manually constructing a target.{triple}.runner key, mirroring how target_linker() already works. This routes through host_config for CompileKind::Host when -Zhost-config is enabled.
  2. host_process() now prepends the runner, mirroring the existing logic in target_process().

I added four new tests to cover the feature.

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-documenting-cargo-itself Area: Cargo's documentation S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 6, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 6, 2026

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, weihanglo

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. Looks pretty complete!

View changes since this review

Copy link
Member

Choose a reason for hiding this comment

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

I understand the the failure already show that it is working, could we have a successful case using the echo_wrapper? Such as having this WRAPPER CALLED: snapshot

cargo/tests/testsuite/build.rs

Lines 4464 to 4474 in b9f0d83

let p = project().file("src/lib.rs", "").build();
let wrapper = tools::echo_wrapper();
p.cargo("build -v")
.env("RUSTC_WRAPPER", &wrapper)
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] `[..]/rustc-echo-wrapper[EXE] rustc --crate-name foo [..]`
WRAPPER CALLED: rustc --crate-name foo [..]
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a commit to handle this.

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

@weihanglo weihanglo enabled auto-merge February 8, 2026 15:13
@nitsky
Copy link
Contributor Author

nitsky commented Feb 8, 2026

@weihanglo any idea why this failed on windows x86_64?

@weihanglo
Copy link
Member

@weihanglo any idea why this failed on windows x86_64?

I guess due to raw string so backlashes in Windows paths were not escaped. Perhaps we can instead use CARGO_HOST_RUNNER=<value> to avoid escaping?

auto-merge was automatically disabled February 9, 2026 15:41

Head branch was pushed to by a user without write access

@nitsky
Copy link
Contributor Author

nitsky commented Feb 9, 2026

@weihanglo fixed, ready for merge?

1 similar comment
@nitsky
Copy link
Contributor Author

nitsky commented Feb 9, 2026

@weihanglo fixed, ready for merge?

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

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

27 commits in fe2f314aef06e688a9517da1ac0577bb1854d01f..0c9e687d237ff04b53ccb67b4ce63e9483789e88
2026-01-30 21:52:01 +0000 to 2026-02-11 05:58:30 +0000
- chore: downgrade to libc@0.2.180 (rust-lang/cargo#16624)
- fix(script): Load config relative to the script (rust-lang/cargo#16620)
- fix(lints): Don't run on-by-default lints when MSRV is too old (rust-lang/cargo#16618)
- fix(build): Remove deprecated, unstable --out-dir (rust-lang/cargo#16608)
- fix(script): Make the lockfile script-specific independent of build-dir (rust-lang/cargo#16619)
- fix(lockfile-path): Respect the config in fix, install (rust-lang/cargo#16617)
- chore: upgrade to gix@0.79.0 (rust-lang/cargo#16615)
- chore: downgrade to libc@0.2.179 (rust-lang/cargo#16613)
- feat(timings): Enable text selection in the charts (rust-lang/cargo#16607)
- Add host.runner for wrapping host build target executions (rust-lang/cargo#16599)
- feat(schema): Add `impl Copy for RustVersion` (rust-lang/cargo#16609)
- refactor(lints): Cleanup (rust-lang/cargo#16610)
- refactor(timings): Remove `CanvasRenderer` in favor of `SvgRenderer` (rust-lang/cargo#16602)
- Fix known hosts parsing (rust-lang/cargo#16596)
- chore: pin openssl-src to 300.5.4 (rust-lang/cargo#16601)
- chore(deps): bump time from 0.3.46 to 0.3.47 (rust-lang/cargo#16593)
- feat(lints): Add missing_lints_inheritance  (rust-lang/cargo#16588)
- chore(deps): bump git2 from 0.20.3 to 0.20.4 (rust-lang/cargo#16589)
- chore(deps): update msrv (3 versions) to v1.91 (rust-lang/cargo#16587)
- feat(lints): Add unused_workspace_package_fields lint (rust-lang/cargo#16585)
- Add command field to BuildStarted in build-analysis (rust-lang/cargo#16577)
- Fix link for lockfile-publish-time (rust-lang/cargo#16582)
- docs(cli): Discuss commands and aliases (rust-lang/cargo#16581)
- fix(script): Correct style of help message (rust-lang/cargo#16580)
- chore(deps): update compatible (rust-lang/cargo#16578)
- chore(deps): update crate-ci/typos action to v1.42.3 (rust-lang/cargo#16579)
- fix(timings): Only compute `y_ticks` when the `units` is not empty. (rust-lang/cargo#16575)
@rustbot rustbot added this to the 1.95.0 milestone Feb 11, 2026
weihanglo added a commit to weihanglo/cargo that referenced this pull request Feb 12, 2026
This is a regression found in rust-lang/compiler-builtins#1087
and introduced by rust-lang#16599

There are other regression that `host.runner` and `host.linker`
are accidentally applied to target builds which I plan to fix
both in a follow-up PR.
(rust-lang#12535 introduced the `host.linker` bug btw)
weihanglo added a commit to weihanglo/cargo that referenced this pull request Feb 12, 2026
This is a regression found in rust-lang/miri#4855
and introduced by rust-lang#16599

There are other regression that `host.runner` and `host.linker`
are accidentally applied to target builds which I plan to fix
both in a follow-up PR.
(rust-lang#12535 introduced the `host.linker` bug btw)
github-merge-queue bot pushed a commit that referenced this pull request Feb 12, 2026
### What does this PR try to resolve?

This is a regression found in rust-lang/compiler-builtins#1087
and introduced by #16599

There are other regression that `host.runner` and `host.linker`
are accidentally applied to target builds which I plan to fix
both in a follow-up PR.
(#12535 introduced the `host.linker` bug btw)
@briansmith
Copy link

There seems to be a lot of fallout from this PR or related changes. It seems like there isn't enough testing of when the CARGO_TARGET_<target>_RUNNER and related settings are supposed to and not supposed to be applied, as the implementation of this feature seems notably different than what was described in the related issue, issue #16591. I think it should be reverted, the intended semantics better documented, and then more tests written to cover the intended semantics.

github-actions bot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Feb 16, 2026
Update cargo submodule

27 commits in fe2f314aef06e688a9517da1ac0577bb1854d01f..0c9e687d237ff04b53ccb67b4ce63e9483789e88
2026-01-30 21:52:01 +0000 to 2026-02-11 05:58:30 +0000
- chore: downgrade to libc@0.2.180 (rust-lang/cargo#16624)
- fix(script): Load config relative to the script (rust-lang/cargo#16620)
- fix(lints): Don't run on-by-default lints when MSRV is too old (rust-lang/cargo#16618)
- fix(build): Remove deprecated, unstable --out-dir (rust-lang/cargo#16608)
- fix(script): Make the lockfile script-specific independent of build-dir (rust-lang/cargo#16619)
- fix(lockfile-path): Respect the config in fix, install (rust-lang/cargo#16617)
- chore: upgrade to gix@0.79.0 (rust-lang/cargo#16615)
- chore: downgrade to libc@0.2.179 (rust-lang/cargo#16613)
- feat(timings): Enable text selection in the charts (rust-lang/cargo#16607)
- Add host.runner for wrapping host build target executions (rust-lang/cargo#16599)
- feat(schema): Add `impl Copy for RustVersion` (rust-lang/cargo#16609)
- refactor(lints): Cleanup (rust-lang/cargo#16610)
- refactor(timings): Remove `CanvasRenderer` in favor of `SvgRenderer` (rust-lang/cargo#16602)
- Fix known hosts parsing (rust-lang/cargo#16596)
- chore: pin openssl-src to 300.5.4 (rust-lang/cargo#16601)
- chore(deps): bump time from 0.3.46 to 0.3.47 (rust-lang/cargo#16593)
- feat(lints): Add missing_lints_inheritance  (rust-lang/cargo#16588)
- chore(deps): bump git2 from 0.20.3 to 0.20.4 (rust-lang/cargo#16589)
- chore(deps): update msrv (3 versions) to v1.91 (rust-lang/cargo#16587)
- feat(lints): Add unused_workspace_package_fields lint (rust-lang/cargo#16585)
- Add command field to BuildStarted in build-analysis (rust-lang/cargo#16577)
- Fix link for lockfile-publish-time (rust-lang/cargo#16582)
- docs(cli): Discuss commands and aliases (rust-lang/cargo#16581)
- fix(script): Correct style of help message (rust-lang/cargo#16580)
- chore(deps): update compatible (rust-lang/cargo#16578)
- chore(deps): update crate-ci/typos action to v1.42.3 (rust-lang/cargo#16579)
- fix(timings): Only compute `y_ticks` when the `units` is not empty. (rust-lang/cargo#16575)
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Feb 16, 2026
Update cargo submodule

27 commits in fe2f314aef06e688a9517da1ac0577bb1854d01f..0c9e687d237ff04b53ccb67b4ce63e9483789e88
2026-01-30 21:52:01 +0000 to 2026-02-11 05:58:30 +0000
- chore: downgrade to libc@0.2.180 (rust-lang/cargo#16624)
- fix(script): Load config relative to the script (rust-lang/cargo#16620)
- fix(lints): Don't run on-by-default lints when MSRV is too old (rust-lang/cargo#16618)
- fix(build): Remove deprecated, unstable --out-dir (rust-lang/cargo#16608)
- fix(script): Make the lockfile script-specific independent of build-dir (rust-lang/cargo#16619)
- fix(lockfile-path): Respect the config in fix, install (rust-lang/cargo#16617)
- chore: upgrade to gix@0.79.0 (rust-lang/cargo#16615)
- chore: downgrade to libc@0.2.179 (rust-lang/cargo#16613)
- feat(timings): Enable text selection in the charts (rust-lang/cargo#16607)
- Add host.runner for wrapping host build target executions (rust-lang/cargo#16599)
- feat(schema): Add `impl Copy for RustVersion` (rust-lang/cargo#16609)
- refactor(lints): Cleanup (rust-lang/cargo#16610)
- refactor(timings): Remove `CanvasRenderer` in favor of `SvgRenderer` (rust-lang/cargo#16602)
- Fix known hosts parsing (rust-lang/cargo#16596)
- chore: pin openssl-src to 300.5.4 (rust-lang/cargo#16601)
- chore(deps): bump time from 0.3.46 to 0.3.47 (rust-lang/cargo#16593)
- feat(lints): Add missing_lints_inheritance  (rust-lang/cargo#16588)
- chore(deps): bump git2 from 0.20.3 to 0.20.4 (rust-lang/cargo#16589)
- chore(deps): update msrv (3 versions) to v1.91 (rust-lang/cargo#16587)
- feat(lints): Add unused_workspace_package_fields lint (rust-lang/cargo#16585)
- Add command field to BuildStarted in build-analysis (rust-lang/cargo#16577)
- Fix link for lockfile-publish-time (rust-lang/cargo#16582)
- docs(cli): Discuss commands and aliases (rust-lang/cargo#16581)
- fix(script): Correct style of help message (rust-lang/cargo#16580)
- chore(deps): update compatible (rust-lang/cargo#16578)
- chore(deps): update crate-ci/typos action to v1.42.3 (rust-lang/cargo#16579)
- fix(timings): Only compute `y_ticks` when the `units` is not empty. (rust-lang/cargo#16575)
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-documenting-cargo-itself Area: Cargo's documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add host.runner for wrapping host build target executions (e.g. build scripts)

5 participants