From 5d88360f9ca2afc207b33adf79b9ea07aa9d25b1 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 12 Feb 2026 12:21:02 +0800 Subject: [PATCH 1/2] test: show targe runner got applied to host build targets This is a regression and will be fixed in the next commit --- tests/testsuite/build_script.rs | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 9a519ece6e2..2ff6646b41a 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -963,6 +963,42 @@ Caused by: .run(); } +#[cargo_test] +fn target_runner_does_not_apply_to_build_script() { + // Regression test for https://github.com/rust-lang/miri/issues/4855 + // `target..runner` should not wrap build scripts. + let target = rustc_host(); + let p = project() + .file( + ".cargo/config.toml", + &format!( + r#" + [target.{target}] + runner = "nonexistent-runner" + "#, + ), + ) + .file("build.rs", "fn main() {}") + .file("src/lib.rs", "") + .build(); + + // FIXME: target runner should not apply to build scripts. + p.cargo("check") + .with_status(101) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[ERROR] failed to run custom build command for `foo v0.0.1 ([ROOT]/foo)` + +Caused by: + could not execute process `nonexistent-runner [ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build` (never executed) + +Caused by: + [NOT_FOUND] + +"#]]) + .run(); +} + #[cargo_test] fn custom_build_script_wrong_rustc_flags() { let p = project() From 9b0fe7ba74bfbbaedb3d7529479917abb7b38add Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 12 Feb 2026 12:48:17 +0800 Subject: [PATCH 2/2] fix: apply `host.runner` only when `host-config` enabled This is a regression found in rust-lang/miri#4855 and introduced by rust-lang/cargo#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/cargo#12535 introduced the `host.linker` bug btw) --- src/cargo/core/compiler/compilation.rs | 6 +++++- tests/testsuite/build_script.rs | 10 +--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index 7ac26dc8bc5..f94d750a18f 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -235,7 +235,11 @@ impl<'gctx> Compilation<'gctx> { cmd: T, pkg: &Package, ) -> CargoResult { - let builder = if let Some((runner, args)) = self.target_runner(CompileKind::Host) { + // Only use host runner when -Zhost-config is enabled + // to ensure `target..runner` does not wrap build scripts. + let builder = if !self.gctx.target_applies_to_host()? + && let Some((runner, args)) = self.target_runner(CompileKind::Host) + { let mut builder = ProcessBuilder::new(runner); builder.args(args); builder.arg(cmd); diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 2ff6646b41a..befd6496893 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -982,18 +982,10 @@ fn target_runner_does_not_apply_to_build_script() { .file("src/lib.rs", "") .build(); - // FIXME: target runner should not apply to build scripts. p.cargo("check") - .with_status(101) .with_stderr_data(str![[r#" [COMPILING] foo v0.0.1 ([ROOT]/foo) -[ERROR] failed to run custom build command for `foo v0.0.1 ([ROOT]/foo)` - -Caused by: - could not execute process `nonexistent-runner [ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build` (never executed) - -Caused by: - [NOT_FOUND] +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s "#]]) .run();