Skip to content

Commit 799a6ab

Browse files
committed
add warning notification on rustup toolchain command
if host toolchain's arch is different with target. Signed-off-by: frbimo <fr.bimo@gmail.com>
1 parent 1863453 commit 799a6ab

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
@@ -1940,3 +1940,25 @@ fn check_host_goes_away() {
19401940
);
19411941
})
19421942
}
1943+
1944+
#[test]
1945+
fn warn_on_unmatch_build() {
1946+
clitools::setup(Scenario::MultiHost, &|config| {
1947+
let arch = clitools::MULTI_ARCH1;
1948+
expect_stderr_ok(
1949+
config,
1950+
&[
1951+
"rustup",
1952+
"toolchain",
1953+
"install",
1954+
&format!("nightly-{}", arch),
1955+
"--no-self-update",
1956+
],
1957+
&format!(
1958+
r"warning: toolchain 'nightly-{0}' may not be able to run on this system.
1959+
warning: If you meant to build software to target that platform, perhaps try `rustup target add {0}` instead?",
1960+
arch,
1961+
),
1962+
);
1963+
});
1964+
}

0 commit comments

Comments
 (0)