Skip to content

Commit aeaeffc

Browse files
committed
refactor(cli/common)!: throw an error when installing a toolchain for an incompatible host
1 parent 7f6ea27 commit aeaeffc

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

src/cli/common.rs

Lines changed: 9 additions & 7 deletions
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,9 @@ 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 the toolchain if it has an incompatible
631+
/// target triple, i.e. might not be able to run on the host system.
632+
pub(crate) fn check_non_host_toolchain(
632633
toolchain: String,
633634
host_arch: &TargetTriple,
634635
target_triple: &TargetTriple,
@@ -637,10 +638,11 @@ pub(crate) fn warn_if_host_is_incompatible(
637638
if force_non_host || host_arch.can_run(target_triple)? {
638639
return Ok(());
639640
}
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(())
641+
Err(RustupError::ToolchainIncompatible {
642+
toolchain,
643+
target_triple: target_triple.clone(),
644+
}
645+
.into())
644646
}
645647

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

src/cli/rustup_mode.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ 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"
90+
)]
91+
ToolchainIncompatible {
92+
toolchain: String,
93+
target_triple: TargetTriple,
94+
},
8795
#[error("toolchain '{0}' is not installable")]
8896
ToolchainNotInstallable(String),
8997
#[error(

0 commit comments

Comments
 (0)