Skip to content

Commit 5674652

Browse files
authored
Merge pull request #2534 from frbimo/warn_download
warn toolchain on different platform
2 parents 8e77e51 + 2d6d88b commit 5674652

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/cli/rustup_mode.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use super::self_update;
1515
use super::term2;
1616
use super::term2::Terminal;
1717
use super::topical_doc;
18-
use crate::dist::dist::{PartialTargetTriple, PartialToolchainDesc, Profile, TargetTriple};
18+
use crate::dist::dist::{
19+
PartialTargetTriple, PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc,
20+
};
1921
use crate::dist::manifest::Component;
2022
use crate::process;
2123
use crate::toolchain::{CustomToolchain, DistributableToolchain};
@@ -904,6 +906,32 @@ fn update(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
904906
if let Some(names) = m.values_of("toolchain") {
905907
for name in names {
906908
update_bare_triple_check(cfg, name)?;
909+
910+
let toolchain_has_triple = match PartialToolchainDesc::from_str(name) {
911+
Ok(x) => x.has_triple(),
912+
_ => false,
913+
};
914+
915+
if toolchain_has_triple {
916+
let host_arch = TargetTriple::from_host_or_build();
917+
match ToolchainDesc::from_str(name) {
918+
Ok(toolchain_desc) => {
919+
let target_triple = toolchain_desc.target;
920+
if host_arch.ne(&target_triple) {
921+
warn!(
922+
"toolchain '{}' may not be able to run on this system.",
923+
name
924+
);
925+
warn!(
926+
"If you meant to build software to target that platform, perhaps try `rustup target add {}` instead?",
927+
target_triple.to_string()
928+
);
929+
}
930+
}
931+
_ => (),
932+
}
933+
}
934+
907935
let toolchain = cfg.get_toolchain(name, false)?;
908936

909937
let status = if !toolchain.is_custom() {

tests/cli-rustup.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,3 +1978,25 @@ fn check_unix_settings_fallback() {
19781978
);
19791979
});
19801980
}
1981+
1982+
#[test]
1983+
fn warn_on_unmatch_build() {
1984+
clitools::setup(Scenario::MultiHost, &|config| {
1985+
let arch = clitools::MULTI_ARCH1;
1986+
expect_stderr_ok(
1987+
config,
1988+
&[
1989+
"rustup",
1990+
"toolchain",
1991+
"install",
1992+
&format!("nightly-{}", arch),
1993+
"--no-self-update",
1994+
],
1995+
&format!(
1996+
r"warning: toolchain 'nightly-{0}' may not be able to run on this system.
1997+
warning: If you meant to build software to target that platform, perhaps try `rustup target add {0}` instead?",
1998+
arch,
1999+
),
2000+
);
2001+
});
2002+
}

0 commit comments

Comments
 (0)