Skip to content

Commit 1353cea

Browse files
committed
install: improve heuristic for deprecation warning
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
1 parent c8be2a3 commit 1353cea

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/cli/rustup_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ fn update(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
962962
let host_arch = TargetTriple::from_host_or_build();
963963
if let Ok(toolchain_desc) = ToolchainDesc::from_str(name) {
964964
let target_triple = toolchain_desc.target;
965-
if !forced && host_arch.ne(&target_triple) {
965+
if !forced && !host_arch.can_run(&target_triple)? {
966966
err!("DEPRECATED: future versions of rustup will require --force-non-host to install a non-host toolchain as the default.");
967967
warn!(
968968
"toolchain '{}' may not be able to run on this system.",

src/dist/dist.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,33 @@ impl TargetTriple {
311311
pub fn from_host_or_build() -> Self {
312312
Self::from_host().unwrap_or_else(Self::from_build)
313313
}
314+
315+
pub fn can_run(&self, other: &TargetTriple) -> Result<bool> {
316+
// Most trivial shortcut of all
317+
if self == other {
318+
return Ok(true);
319+
}
320+
// Otherwise we need to parse things
321+
let partial_self = PartialTargetTriple::new(&self.0)
322+
.ok_or_else(|| anyhow!(format!("Unable to parse target triple: {}", self.0)))?;
323+
let partial_other = PartialTargetTriple::new(&other.0)
324+
.ok_or_else(|| anyhow!(format!("Unable to parse target triple: {}", other.0)))?;
325+
// First obvious check is OS, if that doesn't match there's no chance
326+
let ret = if partial_self.os != partial_other.os {
327+
false
328+
} else if partial_self.os.as_deref() == Some("pc-windows") {
329+
// Windows is a special case here, we know we can run 32bit on 64bit
330+
// and we know we can run gnu and msvc on the same system
331+
// We don't immediately assume we can cross between x86 and aarch64 though
332+
(partial_self.arch == partial_other.arch)
333+
|| (partial_self.arch.as_deref() == Some("x86_64")
334+
&& partial_other.arch.as_deref() == Some("i686"))
335+
} else {
336+
// For other OSes, for now, we assume other toolchains won't run
337+
false
338+
};
339+
Ok(ret)
340+
}
314341
}
315342

316343
impl std::convert::TryFrom<PartialTargetTriple> for TargetTriple {

0 commit comments

Comments
 (0)