Skip to content

Commit 3b0c072

Browse files
committed
refactor(cli/common)!: deny installing a host-incompatible toolchain w/o --force-non-host
1 parent 7f6ea27 commit 3b0c072

File tree

6 files changed

+45
-26
lines changed

6 files changed

+45
-26
lines changed

src/cli/common.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::{
2222
dist::{
2323
manifest::ComponentStatus, notifications as dist_notifications, TargetTriple, ToolchainDesc,
2424
},
25+
errors::RustupError,
2526
install::UpdateStatus,
2627
notifications::Notification,
2728
process::{terminalsource, Process},
@@ -626,9 +627,10 @@ pub(crate) fn ignorable_error(
626627
}
627628
}
628629

629-
/// Warns if rustup is trying to install a toolchain that might not be
630-
/// able to run on the host system.
631-
pub(crate) fn warn_if_host_is_incompatible(
630+
/// Returns an error for a toolchain if:
631+
/// - The toolchain has an incompatible target triple, i.e. might not be able to run on the host system.
632+
/// - The `force_non_host` flag is set to `false`.
633+
pub(crate) fn check_non_host_toolchain(
632634
toolchain: String,
633635
host_arch: &TargetTriple,
634636
target_triple: &TargetTriple,
@@ -637,10 +639,11 @@ pub(crate) fn warn_if_host_is_incompatible(
637639
if force_non_host || host_arch.can_run(target_triple)? {
638640
return Ok(());
639641
}
640-
error!("DEPRECATED: future versions of rustup will require --force-non-host to install a non-host toolchain.");
641-
warn!("toolchain '{toolchain}' may not be able to run on this system.");
642-
warn!("If you meant to build software to target that platform, perhaps try `rustup target add {target_triple}` instead?");
643-
Ok(())
642+
Err(RustupError::ToolchainIncompatible {
643+
toolchain,
644+
target_triple: target_triple.clone(),
645+
}
646+
.into())
644647
}
645648

646649
/// Warns if rustup is running under emulation, such as macOS Rosetta

src/cli/rustup_mode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ async fn update(
837837
if name.has_triple() {
838838
let host_arch = TargetTriple::from_host_or_build(cfg.process);
839839
let target_triple = name.clone().resolve(&host_arch)?.target;
840-
common::warn_if_host_is_incompatible(
840+
common::check_non_host_toolchain(
841841
name.to_string(),
842842
&host_arch,
843843
&target_triple,

src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ impl<'a> Cfg<'a> {
793793
force_non_host: bool,
794794
verbose: bool,
795795
) -> Result<(UpdateStatus, Toolchain<'_>)> {
796-
common::warn_if_host_is_incompatible(
796+
common::check_non_host_toolchain(
797797
toolchain.to_string(),
798798
&TargetTriple::from_host_or_build(self.process),
799799
&toolchain.target,

src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ pub enum RustupError {
8484
},
8585
#[error("command failed: '{}'", PathBuf::from(.name).display())]
8686
RunningCommand { name: OsString },
87+
#[error(
88+
"toolchain '{toolchain}' may not be able to run on this system\n\
89+
note: to build software for that platform, try `rustup target add {target_triple}` instead\n\
90+
note: add the `--force-non-host` flag to install the toolchain anyway"
91+
)]
92+
ToolchainIncompatible {
93+
toolchain: String,
94+
target_triple: TargetTriple,
95+
},
8796
#[error("toolchain '{0}' is not installable")]
8897
ToolchainNotInstallable(String),
8998
#[error(

tests/suite/cli_misc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ async fn multi_host_smoke_test() {
210210
let mut cx = CliTestContext::new(Scenario::MultiHost).await;
211211
let toolchain = format!("nightly-{}", clitools::MULTI_ARCH1);
212212
cx.config
213-
.expect_ok(&["rustup", "default", &toolchain])
213+
.expect_ok(&["rustup", "default", &toolchain, "--force-non-host"])
214214
.await;
215215
cx.config
216216
.expect_stdout_ok(&["rustc", "--version"], "xxxx-nightly-2")

tests/suite/cli_rustup.rs

+23-16
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ async fn show_multiple_targets() {
754754
"rustup",
755755
"default",
756756
&format!("nightly-{}", clitools::MULTI_ARCH1),
757+
"--force-non-host",
757758
])
758759
.await;
759760
cx.config
@@ -801,6 +802,7 @@ async fn show_multiple_toolchains_and_targets() {
801802
"rustup",
802803
"default",
803804
&format!("nightly-{}", clitools::MULTI_ARCH1),
805+
"--force-non-host",
804806
])
805807
.await;
806808
cx.config
@@ -810,6 +812,7 @@ async fn show_multiple_toolchains_and_targets() {
810812
.expect_ok(&[
811813
"rustup",
812814
"update",
815+
"--force-non-host",
813816
&format!("stable-{}", clitools::MULTI_ARCH1),
814817
])
815818
.await;
@@ -2731,29 +2734,33 @@ async fn check_unix_settings_fallback() {
27312734
}
27322735

27332736
#[tokio::test]
2734-
async fn warn_on_unmatch_build() {
2737+
async fn deny_incompatible_toolchain_install() {
27352738
let cx = CliTestContext::new(Scenario::MultiHost).await;
27362739
let arch = clitools::MULTI_ARCH1;
2737-
cx.config.expect_stderr_ok(
2738-
&["rustup", "toolchain", "install", &format!("nightly-{arch}")],
2739-
&format!(
2740-
r"warn: toolchain 'nightly-{arch}' may not be able to run on this system.
2741-
warn: If you meant to build software to target that platform, perhaps try `rustup target add {arch}` instead?",
2742-
),
2743-
).await;
2740+
cx.config
2741+
.expect_err(
2742+
&["rustup", "toolchain", "install", &format!("nightly-{arch}")],
2743+
&format!(
2744+
"error: toolchain 'nightly-{arch}' may not be able to run on this system
2745+
note: to build software for that platform, try `rustup target add {arch}` instead",
2746+
),
2747+
)
2748+
.await;
27442749
}
27452750

27462751
#[tokio::test]
2747-
async fn warn_on_unmatch_build_default() {
2752+
async fn deny_incompatible_toolchain_default() {
27482753
let cx = CliTestContext::new(Scenario::MultiHost).await;
27492754
let arch = clitools::MULTI_ARCH1;
2750-
cx.config.expect_stderr_ok(
2751-
&["rustup", "default", &format!("nightly-{arch}")],
2752-
&format!(
2753-
r"warn: toolchain 'nightly-{arch}' may not be able to run on this system.
2754-
warn: If you meant to build software to target that platform, perhaps try `rustup target add {arch}` instead?",
2755-
),
2756-
).await;
2755+
cx.config
2756+
.expect_err(
2757+
&["rustup", "default", &format!("nightly-{arch}")],
2758+
&format!(
2759+
"error: toolchain 'nightly-{arch}' may not be able to run on this system
2760+
note: to build software for that platform, try `rustup target add {arch}` instead",
2761+
),
2762+
)
2763+
.await;
27572764
}
27582765

27592766
#[tokio::test]

0 commit comments

Comments
 (0)