Skip to content
Open
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
14 changes: 3 additions & 11 deletions src/cargo/util/config/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,10 @@ pub(super) fn load_target_cfgs(config: &Config) -> CargoResult<Vec<(String, Targ

/// Returns true if the `[target]` table should be applied to host targets.
pub(super) fn get_target_applies_to_host(config: &Config) -> CargoResult<bool> {
if config.cli_unstable().target_applies_to_host {
if let Ok(target_applies_to_host) = config.get::<bool>("target-applies-to-host") {
Ok(target_applies_to_host)
} else {
Ok(!config.cli_unstable().host_config)
}
} else if config.cli_unstable().host_config {
anyhow::bail!(
"the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set"
);
if let Ok(target_applies_to_host) = config.get::<bool>("target-applies-to-host") {
Ok(target_applies_to_host)
} else {
Ok(true)
Ok(!config.cli_unstable().host_config)
}
}

Expand Down
36 changes: 13 additions & 23 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,7 @@ fn custom_build_env_var_rustc_linker_host_target() {

// no crate type set => linker never called => build succeeds if and
// only if build.rs succeeds, despite linker binary not existing.
p.cargo("build -Z target-applies-to-host --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["target-applies-to-host"])
.run();
p.cargo("build --target").arg(&target).run();
}

#[cargo_test]
Expand Down Expand Up @@ -549,10 +546,9 @@ fn custom_build_env_var_rustc_linker_host_target_env() {

// no crate type set => linker never called => build succeeds if and
// only if build.rs succeeds, despite linker binary not existing.
p.cargo("build -Z target-applies-to-host --target")
p.cargo("build --target")
.env("CARGO_TARGET_APPLIES_TO_HOST", "false")
.arg(&target)
.masquerade_as_nightly_cargo(&["target-applies-to-host"])
.run();
}

Expand All @@ -574,16 +570,10 @@ fn custom_build_invalid_host_config_feature_flag() {
.file("src/lib.rs", "")
.build();

// build.rs should fail due to -Zhost-config being set without -Ztarget-applies-to-host
// build.rs should not fail due to -Zhost-config being set
p.cargo("build -Z host-config --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["host-config"])
.with_status(101)
.with_stderr_contains(
"\
error: the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set
",
)
.run();
}

Expand All @@ -608,9 +598,9 @@ fn custom_build_linker_host_target_with_bad_host_config() {
.build();

// build.rs should fail due to bad host linker being set
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
p.cargo("build -Z host-config --verbose --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
.masquerade_as_nightly_cargo(&["host-config"])
.with_status(101)
.with_stderr_contains(
"\
Expand Down Expand Up @@ -643,9 +633,9 @@ fn custom_build_linker_bad_host() {
.build();

// build.rs should fail due to bad host linker being set
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
p.cargo("build -Z host-config --verbose --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
.masquerade_as_nightly_cargo(&["host-config"])
.with_status(101)
.with_stderr_contains(
"\
Expand Down Expand Up @@ -680,9 +670,9 @@ fn custom_build_linker_bad_host_with_arch() {
.build();

// build.rs should fail due to bad host linker being set
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
p.cargo("build -Z host-config --verbose --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
.masquerade_as_nightly_cargo(&["host-config"])
.with_status(101)
.with_stderr_contains(
"\
Expand Down Expand Up @@ -726,9 +716,9 @@ fn custom_build_env_var_rustc_linker_cross_arch_host() {

// build.rs should be built fine since cross target != host target.
// assertion should succeed since it's still passed the target linker
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
p.cargo("build -Z host-config --verbose --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
.masquerade_as_nightly_cargo(&["host-config"])
.run();
}

Expand Down Expand Up @@ -756,9 +746,9 @@ fn custom_build_linker_bad_cross_arch_host() {
.build();

// build.rs should fail due to bad host linker being set
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
p.cargo("build -Z host-config --verbose --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
.masquerade_as_nightly_cargo(&["host-config"])
.with_status(101)
.with_stderr_contains(
"\
Expand Down