diff --git a/src/install.rs b/src/install.rs index 005f7a5b2fd..b444c2216aa 100644 --- a/src/install.rs +++ b/src/install.rs @@ -70,6 +70,22 @@ impl<'a> InstallMethod<'a> { )); } + match self { + InstallMethod::Dist { desc, .. } => { + let host_arch = dist::TargetTriple::from_host_or_build(); + let target_triple = desc.target.clone(); + if host_arch.ne(&target_triple) { + (toolchain.cfg().notify_handler)(RootNotification::UnmatchToolchain( + &toolchain.name(), + )); + (toolchain.cfg().notify_handler)(RootNotification::SuggestTarget( + &target_triple.to_string(), + )); + } + } + _ => (), + }; + let status = match (updated, previous_version) { (true, None) => UpdateStatus::Installed, (true, Some(v)) => UpdateStatus::Updated(v), diff --git a/src/notifications.rs b/src/notifications.rs index 3722c1f5c0c..09d99b778df 100644 --- a/src/notifications.rs +++ b/src/notifications.rs @@ -33,6 +33,8 @@ pub enum Notification<'a> { UpgradeRemovesToolchains, MissingFileDuringSelfUninstall(PathBuf), PlainVerboseMessage(&'a str), + UnmatchToolchain(&'a str), + SuggestTarget(&'a str), } impl<'a> From> for Notification<'a> { @@ -77,7 +79,10 @@ impl<'a> Notification<'a> { | UpgradingMetadata(_, _) | MetadataUpgradeNotNeeded(_) => NotificationLevel::Info, NonFatalError(_) => NotificationLevel::Error, - UpgradeRemovesToolchains | MissingFileDuringSelfUninstall(_) => NotificationLevel::Warn, + UpgradeRemovesToolchains + | MissingFileDuringSelfUninstall(_) + | UnmatchToolchain(_) + | SuggestTarget(_) => NotificationLevel::Warn, } } } @@ -130,6 +135,8 @@ impl<'a> Display for Notification<'a> { p.display() ), PlainVerboseMessage(r) => write!(f, "{}", r), + UnmatchToolchain(name) => write!(f, "toolchain '{}' may not be able to run on this system.", name), + SuggestTarget(t)=>write!(f,"If you meant to build software to target that platform, perhaps try `rustup target add {}` instead?",t) } } } diff --git a/tests/cli-rustup.rs b/tests/cli-rustup.rs index 782948a5607..fbb612b31bf 100644 --- a/tests/cli-rustup.rs +++ b/tests/cli-rustup.rs @@ -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, + ), + ); + }); +}