Skip to content

Commit 0cc2206

Browse files
committed
Stabilize target-applies-to-host feature.
Details: #9453, #9322
1 parent b1b25a0 commit 0cc2206

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
@@ -402,10 +402,7 @@ fn custom_build_env_var_rustc_linker_host_target() {
402402

403403
// no crate type set => linker never called => build succeeds if and
404404
// only if build.rs succeeds, despite linker binary not existing.
405-
p.cargo("build -Z target-applies-to-host --target")
406-
.arg(&target)
407-
.masquerade_as_nightly_cargo(&["target-applies-to-host"])
408-
.run();
405+
p.cargo("build --target").arg(&target).run();
409406
}
410407

411408
#[cargo_test]
@@ -437,10 +434,9 @@ fn custom_build_env_var_rustc_linker_host_target_env() {
437434

438435
// no crate type set => linker never called => build succeeds if and
439436
// only if build.rs succeeds, despite linker binary not existing.
440-
p.cargo("build -Z target-applies-to-host --target")
437+
p.cargo("build --target")
441438
.env("CARGO_TARGET_APPLIES_TO_HOST", "false")
442439
.arg(&target)
443-
.masquerade_as_nightly_cargo(&["target-applies-to-host"])
444440
.run();
445441
}
446442

@@ -462,16 +458,10 @@ fn custom_build_invalid_host_config_feature_flag() {
462458
.file("src/lib.rs", "")
463459
.build();
464460

465-
// build.rs should fail due to -Zhost-config being set without -Ztarget-applies-to-host
461+
// build.rs should not fail due to -Zhost-config being set
466462
p.cargo("build -Z host-config --target")
467463
.arg(&target)
468464
.masquerade_as_nightly_cargo(&["host-config"])
469-
.with_status(101)
470-
.with_stderr_contains(
471-
"\
472-
error: the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set
473-
",
474-
)
475465
.run();
476466
}
477467

@@ -496,9 +486,9 @@ fn custom_build_linker_host_target_with_bad_host_config() {
496486
.build();
497487

498488
// build.rs should fail due to bad host linker being set
499-
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
489+
p.cargo("build -Z host-config --verbose --target")
500490
.arg(&target)
501-
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
491+
.masquerade_as_nightly_cargo(&["host-config"])
502492
.with_status(101)
503493
.with_stderr_contains(
504494
"\
@@ -531,9 +521,9 @@ fn custom_build_linker_bad_host() {
531521
.build();
532522

533523
// build.rs should fail due to bad host linker being set
534-
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
524+
p.cargo("build -Z host-config --verbose --target")
535525
.arg(&target)
536-
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
526+
.masquerade_as_nightly_cargo(&["host-config"])
537527
.with_status(101)
538528
.with_stderr_contains(
539529
"\
@@ -568,9 +558,9 @@ fn custom_build_linker_bad_host_with_arch() {
568558
.build();
569559

570560
// build.rs should fail due to bad host linker being set
571-
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
561+
p.cargo("build -Z host-config --verbose --target")
572562
.arg(&target)
573-
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
563+
.masquerade_as_nightly_cargo(&["host-config"])
574564
.with_status(101)
575565
.with_stderr_contains(
576566
"\
@@ -614,9 +604,9 @@ fn custom_build_env_var_rustc_linker_cross_arch_host() {
614604

615605
// build.rs should be built fine since cross target != host target.
616606
// assertion should succeed since it's still passed the target linker
617-
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
607+
p.cargo("build -Z host-config --verbose --target")
618608
.arg(&target)
619-
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
609+
.masquerade_as_nightly_cargo(&["host-config"])
620610
.run();
621611
}
622612

@@ -644,9 +634,9 @@ fn custom_build_linker_bad_cross_arch_host() {
644634
.build();
645635

646636
// build.rs should fail due to bad host linker being set
647-
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
637+
p.cargo("build -Z host-config --verbose --target")
648638
.arg(&target)
649-
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
639+
.masquerade_as_nightly_cargo(&["host-config"])
650640
.with_status(101)
651641
.with_stderr_contains(
652642
"\

0 commit comments

Comments
 (0)