From 0cc2206db67aaf29813c86ea7ce6b40dc9a79dee 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 | 36 ++++++++++++--------------------- 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/src/cargo/util/config/target.rs b/src/cargo/util/config/target.rs index 8190529a6860..3090f13cd735 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 8157b9e73aa7..9b7404f47010 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(&["target-applies-to-host"]) - .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(&["target-applies-to-host"]) .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(&["host-config"]) - .with_status(101) - .with_stderr_contains( - "\ -error: the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set -", - ) .run(); } @@ -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( "\ @@ -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( "\ @@ -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( "\ @@ -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(); } @@ -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( "\