From 923d6eb5566a2dff246316339502f9480a2b1af4 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Sat, 20 Jun 2026 01:05:14 -0400 Subject: [PATCH 1/5] refactor: extract host-only config predicate --- .../compiler/build_context/target_info.rs | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index f843b6dbc4e..d6122f6e4b6 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -783,24 +783,8 @@ fn extra_args( kind: CompileKind, flags: Flags, ) -> CargoResult> { - let target_applies_to_host = gctx.target_applies_to_host()?; - - // Host artifacts should not generally pick up rustflags from anywhere except [host]. - // - // The one exception to this is if `target-applies-to-host = true`, which opts into a - // particular (inconsistent) past Cargo behavior where host artifacts _do_ pick up rustflags - // set elsewhere when `--target` isn't passed. - if kind.is_host() { - if target_applies_to_host && requested_kinds == [CompileKind::Host] { - // This is the past Cargo behavior where we fall back to the same logic as for other - // artifacts without --target. - } else { - // In all other cases, host artifacts just get flags from [host], regardless of - // --target. Or, phrased differently, no `--target` behaves the same as `--target - // `, and host artifacts are always "special" (they don't pick up `RUSTFLAGS` for - // example). - return Ok(rustflags_from_host(gctx, flags, host_triple)?.unwrap_or_else(Vec::new)); - } + if host_artifact_uses_only_host_config(gctx, requested_kinds, kind)? { + return Ok(rustflags_from_host(gctx, flags, host_triple)?.unwrap_or_else(Vec::new)); } // All other artifacts pick up the RUSTFLAGS, [target.*], and [build], in that order. @@ -923,6 +907,35 @@ fn rustflags_from_build(gctx: &GlobalContext, flag: Flags) -> CargoResult