Skip to content

Commit 6b0988c

Browse files
committed
Stabilize target-applies-to-host feature.
Details: #9453, #9322
1 parent 7bf43f0 commit 6b0988c

File tree

2 files changed

+16
-34
lines changed

2 files changed

+16
-34
lines changed

src/cargo/util/config/target.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,10 @@ pub(super) fn load_target_cfgs(config: &Config) -> CargoResult<Vec<(String, Targ
6666

6767
/// Returns true if the `[target]` table should be applied to host targets.
6868
pub(super) fn get_target_applies_to_host(config: &Config) -> CargoResult<bool> {
69-
if config.cli_unstable().target_applies_to_host {
70-
if let Ok(target_applies_to_host) = config.get::<bool>("target-applies-to-host") {
71-
Ok(target_applies_to_host)
72-
} else {
73-
Ok(!config.cli_unstable().host_config)
74-
}
75-
} else if config.cli_unstable().host_config {
76-
anyhow::bail!(
77-
"the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set"
78-
);
69+
if let Ok(target_applies_to_host) = config.get::<bool>("target-applies-to-host") {
70+
Ok(target_applies_to_host)
7971
} else {
80-
Ok(true)
72+
Ok(!config.cli_unstable().host_config)
8173
}
8274
}
8375

tests/testsuite/build_script.rs

+13-23
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,7 @@ fn custom_build_env_var_rustc_linker_host_target() {
514514

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

523520
#[cargo_test]
@@ -549,10 +546,9 @@ fn custom_build_env_var_rustc_linker_host_target_env() {
549546

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

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

577-
// build.rs should fail due to -Zhost-config being set without -Ztarget-applies-to-host
573+
// build.rs should not fail due to -Zhost-config being set
578574
p.cargo("build -Z host-config --target")
579575
.arg(&target)
580576
.masquerade_as_nightly_cargo(&["host-config"])
581-
.with_status(101)
582-
.with_stderr_contains(
583-
"\
584-
error: the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set
585-
",
586-
)
587577
.run();
588578
}
589579

@@ -608,9 +598,9 @@ fn custom_build_linker_host_target_with_bad_host_config() {
608598
.build();
609599

610600
// build.rs should fail due to bad host linker being set
611-
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
601+
p.cargo("build -Z host-config --verbose --target")
612602
.arg(&target)
613-
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
603+
.masquerade_as_nightly_cargo(&["host-config"])
614604
.with_status(101)
615605
.with_stderr_contains(
616606
"\
@@ -643,9 +633,9 @@ fn custom_build_linker_bad_host() {
643633
.build();
644634

645635
// build.rs should fail due to bad host linker being set
646-
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
636+
p.cargo("build -Z host-config --verbose --target")
647637
.arg(&target)
648-
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
638+
.masquerade_as_nightly_cargo(&["host-config"])
649639
.with_status(101)
650640
.with_stderr_contains(
651641
"\
@@ -680,9 +670,9 @@ fn custom_build_linker_bad_host_with_arch() {
680670
.build();
681671

682672
// build.rs should fail due to bad host linker being set
683-
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
673+
p.cargo("build -Z host-config --verbose --target")
684674
.arg(&target)
685-
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
675+
.masquerade_as_nightly_cargo(&["host-config"])
686676
.with_status(101)
687677
.with_stderr_contains(
688678
"\
@@ -726,9 +716,9 @@ fn custom_build_env_var_rustc_linker_cross_arch_host() {
726716

727717
// build.rs should be built fine since cross target != host target.
728718
// assertion should succeed since it's still passed the target linker
729-
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
719+
p.cargo("build -Z host-config --verbose --target")
730720
.arg(&target)
731-
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
721+
.masquerade_as_nightly_cargo(&["host-config"])
732722
.run();
733723
}
734724

@@ -756,9 +746,9 @@ fn custom_build_linker_bad_cross_arch_host() {
756746
.build();
757747

758748
// build.rs should fail due to bad host linker being set
759-
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
749+
p.cargo("build -Z host-config --verbose --target")
760750
.arg(&target)
761-
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
751+
.masquerade_as_nightly_cargo(&["host-config"])
762752
.with_status(101)
763753
.with_stderr_contains(
764754
"\

0 commit comments

Comments
 (0)