Skip to content

Commit

Permalink
add warning notification on rustup toolchain command
Browse files Browse the repository at this point in the history
if host toolchain's arch is different with target.

Signed-off-by: frbimo <[email protected]>
  • Loading branch information
frbimo authored and kinnison committed Nov 17, 2020
1 parent 8e77e51 commit 2d6d88b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use super::self_update;
use super::term2;
use super::term2::Terminal;
use super::topical_doc;
use crate::dist::dist::{PartialTargetTriple, PartialToolchainDesc, Profile, TargetTriple};
use crate::dist::dist::{
PartialTargetTriple, PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc,
};
use crate::dist::manifest::Component;
use crate::process;
use crate::toolchain::{CustomToolchain, DistributableToolchain};
Expand Down Expand Up @@ -904,6 +906,32 @@ fn update(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
if let Some(names) = m.values_of("toolchain") {
for name in names {
update_bare_triple_check(cfg, name)?;

let toolchain_has_triple = match PartialToolchainDesc::from_str(name) {
Ok(x) => x.has_triple(),
_ => false,
};

if toolchain_has_triple {
let host_arch = TargetTriple::from_host_or_build();
match ToolchainDesc::from_str(name) {
Ok(toolchain_desc) => {
let target_triple = toolchain_desc.target;
if host_arch.ne(&target_triple) {
warn!(
"toolchain '{}' may not be able to run on this system.",
name
);
warn!(
"If you meant to build software to target that platform, perhaps try `rustup target add {}` instead?",
target_triple.to_string()
);
}
}
_ => (),
}
}

let toolchain = cfg.get_toolchain(name, false)?;

let status = if !toolchain.is_custom() {
Expand Down
22 changes: 22 additions & 0 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1978,3 +1978,25 @@ fn check_unix_settings_fallback() {
);
});
}

#[test]
fn warn_on_unmatch_build() {
clitools::setup(Scenario::MultiHost, &|config| {
let arch = clitools::MULTI_ARCH1;
expect_stderr_ok(
config,
&[
"rustup",
"toolchain",
"install",
&format!("nightly-{}", arch),
"--no-self-update",
],
&format!(
r"warning: toolchain 'nightly-{0}' may not be able to run on this system.
warning: If you meant to build software to target that platform, perhaps try `rustup target add {0}` instead?",
arch,
),
);
});
}

0 comments on commit 2d6d88b

Please sign in to comment.