Skip to content

Commit

Permalink
warn toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
frbimo committed Oct 22, 2020
1 parent 1863453 commit 3db2cb9
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.clone();
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 @@ -1940,3 +1940,25 @@ fn check_host_goes_away() {
);
})
}

#[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 3db2cb9

Please sign in to comment.