diff --git a/src/cargo/core/compiler/build_context/mod.rs b/src/cargo/core/compiler/build_context/mod.rs index edca6d5d2ac..e940d7b7d86 100644 --- a/src/cargo/core/compiler/build_context/mod.rs +++ b/src/cargo/core/compiler/build_context/mod.rs @@ -21,6 +21,7 @@ pub use self::target_info::FileFlavor; pub use self::target_info::FileType; pub use self::target_info::RustcTargetData; pub use self::target_info::TargetInfo; +pub(crate) use self::target_info::host_artifact_uses_only_host_config; /// The build context, containing complete information needed for a build task /// before it gets started. 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