Skip to content

Commit 31c8a18

Browse files
committed
refactor(rustup-mode): extract warn_if_host_is_incompatible()
1 parent 425709c commit 31c8a18

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/cli/common.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,22 @@ pub(crate) fn ignorable_error(
634634
}
635635
}
636636

637+
/// Warns if rustup is trying to install a toolchain that might not be
638+
/// able to run on the host system.
639+
pub(crate) fn warn_if_host_is_incompatible(
640+
toolchain: impl Display,
641+
host_arch: &TargetTriple,
642+
target_triple: &TargetTriple,
643+
force_non_host: bool,
644+
) -> Result<()> {
645+
if !force_non_host && !host_arch.can_run(target_triple)? {
646+
error!("DEPRECATED: future versions of rustup will require --force-non-host to install a non-host toolchain.");
647+
warn!("toolchain '{toolchain}' may not be able to run on this system.");
648+
warn!("If you meant to build software to target that platform, perhaps try `rustup target add {target_triple}` instead?");
649+
}
650+
Ok(())
651+
}
652+
637653
/// Warns if rustup is running under emulation, such as macOS Rosetta
638654
pub(crate) fn warn_if_host_is_emulated(process: &Process) {
639655
if TargetTriple::is_host_emulated() {

src/cli/rustup_mode.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use anyhow::{anyhow, Error, Result};
99
use clap::{builder::PossibleValue, Args, CommandFactory, Parser, Subcommand, ValueEnum};
1010
use clap_complete::Shell;
1111
use itertools::Itertools;
12-
use tracing::{error, info, trace, warn};
12+
use tracing::{info, trace, warn};
1313

1414
use crate::{
1515
cli::{
@@ -817,16 +817,8 @@ async fn update(cfg: &mut Cfg<'_>, opts: UpdateOpts) -> Result<utils::ExitCode>
817817
// This needs another pass to fix it all up
818818
if name.has_triple() {
819819
let host_arch = TargetTriple::from_host_or_build(cfg.process);
820-
821820
let target_triple = name.clone().resolve(&host_arch)?.target;
822-
if !forced && !host_arch.can_run(&target_triple)? {
823-
error!("DEPRECATED: future versions of rustup will require --force-non-host to install a non-host toolchain.");
824-
warn!("toolchain '{name}' may not be able to run on this system.");
825-
warn!(
826-
"If you meant to build software to target that platform, perhaps try `rustup target add {}` instead?",
827-
target_triple.to_string()
828-
);
829-
}
821+
common::warn_if_host_is_incompatible(&name, &host_arch, &target_triple, forced)?;
830822
}
831823
let desc = name.resolve(&cfg.get_default_host_triple()?)?;
832824

0 commit comments

Comments
 (0)