Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,25 @@ impl<'gctx> Compilation<'gctx> {
let primary_rustc_process = bcx.build_config.primary_unit_rustc.clone();
let rustc_workspace_wrapper_process = bcx.rustc().workspace_process();
let host = bcx.host_triple().to_string();

// When `target-applies-to-host=false`, and without `--target`,
// there will be only `CompileKind::Host` in requested_kinds.
// Need to insert target config explicitly for target-applies-to-host=false
// to find the correct configs.
let insert_explicit_host_runner = !bcx.gctx.target_applies_to_host()?
&& bcx
.build_config
.requested_kinds
.iter()
.any(CompileKind::is_host);
let mut runners = bcx
.build_config
.requested_kinds
.iter()
.chain(Some(&CompileKind::Host))
.map(|kind| Ok((*kind, target_runner(bcx, *kind)?)))
.collect::<CargoResult<HashMap<_, _>>>()?;
if !bcx.gctx.target_applies_to_host()? {
// When `target-applies-to-host=false`, and without `--target`,
// there will be only `CompileKind::Host` in requested_kinds.
// Need to insert target config explicitly for target-applies-to-host=false
// to find the correct configs.
if insert_explicit_host_runner {
let kind = explicit_host_kind(&host);
runners.insert(kind, target_runner(bcx, kind)?);
}
Expand All @@ -167,8 +174,7 @@ impl<'gctx> Compilation<'gctx> {
.chain(Some(&CompileKind::Host))
.map(|kind| Ok((*kind, target_linker(bcx, *kind)?)))
.collect::<CargoResult<HashMap<_, _>>>()?;
if !bcx.gctx.target_applies_to_host()? {
// See above reason in runner why we do this.
if insert_explicit_host_runner {
let kind = explicit_host_kind(&host);
linkers.insert(kind, target_linker(bcx, kind)?);
}
Expand Down
18 changes: 18 additions & 0 deletions tests/testsuite/cross_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,7 @@ fn host_linker_does_not_apply_to_binary_build() {
// host.linker should not be applied but target.linker
p.cargo("build -Z target-applies-to-host -Z host-config")
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
.env("CARGO_TARGET_APPLIES_TO_HOST", "false")
.with_status(101)
// Need to omit some MSVC-specific diagnostics
// because rustc prints extra stuff when linker was not found.
Expand All @@ -1352,3 +1353,20 @@ fn host_linker_does_not_apply_to_binary_build() {
"#]])
.run();
}

#[cargo_test]
fn cross_with_host_config() {
if cross_compile_disabled() {
return;
}

let target = cross_compile::alternate();

let p = project().file("src/main.rs", "fn main() {}").build();

p.cargo("build -Z target-applies-to-host -Z host-config --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
.with_status(0)
.run();
}