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 Mar 1, 2022
1 parent 489b66f commit a5f2401
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 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
26 changes: 8 additions & 18 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()
.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()
.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()
.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,7 +486,7 @@ 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()
.with_status(101)
Expand Down Expand Up @@ -531,7 +521,7 @@ 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()
.with_status(101)
Expand Down Expand Up @@ -568,7 +558,7 @@ 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()
.with_status(101)
Expand Down Expand Up @@ -614,7 +604,7 @@ 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()
.run();
Expand Down Expand Up @@ -644,7 +634,7 @@ 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()
.with_status(101)
Expand Down

0 comments on commit a5f2401

Please sign in to comment.