Skip to content

Commit

Permalink
Stabilize target-applies-to-host feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshilliard committed Oct 21, 2022
1 parent b1b25a0 commit 0cc2206
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 34 deletions.
14 changes: 3 additions & 11 deletions src/cargo/util/config/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,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 @@ -402,10 +402,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 @@ -437,10 +434,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 @@ -462,16 +458,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 @@ -496,9 +486,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 @@ -531,9 +521,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 @@ -568,9 +558,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 @@ -614,9 +604,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 @@ -644,9 +634,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

0 comments on commit 0cc2206

Please sign in to comment.