From a5f24011ea097fc3e4a97969c6c3e904b4061490 Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Sun, 1 Aug 2021 17:38:32 -0600 Subject: [PATCH] Stabilize target-applies-to-host feature. Details: #9453, #9322 --- src/cargo/util/config/target.rs | 14 +++----------- tests/testsuite/build_script.rs | 26 ++++++++------------------ 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/src/cargo/util/config/target.rs b/src/cargo/util/config/target.rs index 21089ce491b4..c41aa170d837 100644 --- a/src/cargo/util/config/target.rs +++ b/src/cargo/util/config/target.rs @@ -67,18 +67,10 @@ pub(super) fn load_target_cfgs(config: &Config) -> CargoResult CargoResult { - if config.cli_unstable().target_applies_to_host { - if let Ok(target_applies_to_host) = config.get::("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::("target-applies-to-host") { + Ok(target_applies_to_host) } else { - Ok(true) + Ok(!config.cli_unstable().host_config) } } diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index d0ef3a2e727a..2628b1d355e0 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -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] @@ -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(); } @@ -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(); } @@ -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) @@ -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) @@ -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) @@ -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(); @@ -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)