Skip to content

Commit 3c7652c

Browse files
committed
Stabilize target-applies-to-host feature.
Details: #9453, #9322
1 parent 7bdb969 commit 3c7652c

File tree

2 files changed

+16
-34
lines changed

2 files changed

+16
-34
lines changed

src/cargo/util/config/target.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,10 @@ pub(super) fn load_target_cfgs(config: &Config) -> CargoResult<Vec<(String, Targ
6767

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

tests/testsuite/build_script.rs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,7 @@ fn custom_build_env_var_rustc_linker_host_target() {
421421

422422
// no crate type set => linker never called => build succeeds if and
423423
// only if build.rs succeeds, despite linker binary not existing.
424-
p.cargo("build -Z target-applies-to-host --target")
425-
.arg(&target)
426-
.masquerade_as_nightly_cargo(&["target-applies-to-host"])
427-
.run();
424+
p.cargo("build --target").arg(&target).run();
428425
}
429426

430427
#[cargo_test]
@@ -456,10 +453,9 @@ fn custom_build_env_var_rustc_linker_host_target_env() {
456453

457454
// no crate type set => linker never called => build succeeds if and
458455
// only if build.rs succeeds, despite linker binary not existing.
459-
p.cargo("build -Z target-applies-to-host --target")
456+
p.cargo("build --target")
460457
.env("CARGO_TARGET_APPLIES_TO_HOST", "false")
461458
.arg(&target)
462-
.masquerade_as_nightly_cargo(&["target-applies-to-host"])
463459
.run();
464460
}
465461

@@ -481,16 +477,10 @@ fn custom_build_invalid_host_config_feature_flag() {
481477
.file("src/lib.rs", "")
482478
.build();
483479

484-
// build.rs should fail due to -Zhost-config being set without -Ztarget-applies-to-host
480+
// build.rs should not fail due to -Zhost-config being set
485481
p.cargo("build -Z host-config --target")
486482
.arg(&target)
487483
.masquerade_as_nightly_cargo(&["host-config"])
488-
.with_status(101)
489-
.with_stderr_contains(
490-
"\
491-
error: the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set
492-
",
493-
)
494484
.run();
495485
}
496486

@@ -515,9 +505,9 @@ fn custom_build_linker_host_target_with_bad_host_config() {
515505
.build();
516506

517507
// build.rs should fail due to bad host linker being set
518-
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
508+
p.cargo("build -Z host-config --verbose --target")
519509
.arg(&target)
520-
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
510+
.masquerade_as_nightly_cargo(&["host-config"])
521511
.with_status(101)
522512
.with_stderr_contains(
523513
"\
@@ -550,9 +540,9 @@ fn custom_build_linker_bad_host() {
550540
.build();
551541

552542
// build.rs should fail due to bad host linker being set
553-
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
543+
p.cargo("build -Z host-config --verbose --target")
554544
.arg(&target)
555-
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
545+
.masquerade_as_nightly_cargo(&["host-config"])
556546
.with_status(101)
557547
.with_stderr_contains(
558548
"\
@@ -587,9 +577,9 @@ fn custom_build_linker_bad_host_with_arch() {
587577
.build();
588578

589579
// build.rs should fail due to bad host linker being set
590-
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
580+
p.cargo("build -Z host-config --verbose --target")
591581
.arg(&target)
592-
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
582+
.masquerade_as_nightly_cargo(&["host-config"])
593583
.with_status(101)
594584
.with_stderr_contains(
595585
"\
@@ -633,9 +623,9 @@ fn custom_build_env_var_rustc_linker_cross_arch_host() {
633623

634624
// build.rs should be built fine since cross target != host target.
635625
// assertion should succeed since it's still passed the target linker
636-
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
626+
p.cargo("build -Z host-config --verbose --target")
637627
.arg(&target)
638-
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
628+
.masquerade_as_nightly_cargo(&["host-config"])
639629
.run();
640630
}
641631

@@ -663,9 +653,9 @@ fn custom_build_linker_bad_cross_arch_host() {
663653
.build();
664654

665655
// build.rs should fail due to bad host linker being set
666-
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
656+
p.cargo("build -Z host-config --verbose --target")
667657
.arg(&target)
668-
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
658+
.masquerade_as_nightly_cargo(&["host-config"])
669659
.with_status(101)
670660
.with_stderr_contains(
671661
"\

0 commit comments

Comments
 (0)