Skip to content

Commit 64abf6f

Browse files
committed
warn toolchain
1 parent 1863453 commit 64abf6f

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/install.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ impl<'a> InstallMethod<'a> {
7070
));
7171
}
7272

73+
match self {
74+
InstallMethod::Dist { desc, .. } => {
75+
let host_arch = dist::TargetTriple::from_host_or_build();
76+
let target_triple = desc.target.clone();
77+
if host_arch.ne(&target_triple) {
78+
(toolchain.cfg().notify_handler)(RootNotification::UnmatchToolchain(
79+
&toolchain.name(),
80+
));
81+
(toolchain.cfg().notify_handler)(RootNotification::SuggestTarget(
82+
&target_triple.to_string(),
83+
));
84+
}
85+
}
86+
_ => (),
87+
};
88+
7389
let status = match (updated, previous_version) {
7490
(true, None) => UpdateStatus::Installed,
7591
(true, Some(v)) => UpdateStatus::Updated(v),

src/notifications.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub enum Notification<'a> {
3333
UpgradeRemovesToolchains,
3434
MissingFileDuringSelfUninstall(PathBuf),
3535
PlainVerboseMessage(&'a str),
36+
UnmatchToolchain(&'a str),
37+
SuggestTarget(&'a str),
3638
}
3739

3840
impl<'a> From<crate::dist::Notification<'a>> for Notification<'a> {
@@ -77,7 +79,10 @@ impl<'a> Notification<'a> {
7779
| UpgradingMetadata(_, _)
7880
| MetadataUpgradeNotNeeded(_) => NotificationLevel::Info,
7981
NonFatalError(_) => NotificationLevel::Error,
80-
UpgradeRemovesToolchains | MissingFileDuringSelfUninstall(_) => NotificationLevel::Warn,
82+
UpgradeRemovesToolchains
83+
| MissingFileDuringSelfUninstall(_)
84+
| UnmatchToolchain(_)
85+
| SuggestTarget(_) => NotificationLevel::Warn,
8186
}
8287
}
8388
}
@@ -130,6 +135,8 @@ impl<'a> Display for Notification<'a> {
130135
p.display()
131136
),
132137
PlainVerboseMessage(r) => write!(f, "{}", r),
138+
UnmatchToolchain(name) => write!(f, "toolchain '{}' may not be able to run on this system.", name),
139+
SuggestTarget(t)=>write!(f,"If you meant to build software to target that platform, perhaps try `rustup target add {}` instead?",t)
133140
}
134141
}
135142
}

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)