Skip to content

Commit 032bbdc

Browse files
Merge #1193
1193: suggest reinstalling the toolchain r=Emilgardis a=Emilgardis also fixes suggestion when using wrong channel resolves #1192 Co-authored-by: Emil Gardström <[email protected]>
2 parents 202013b + 6219c40 commit 032bbdc

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

src/lib.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,7 @@ pub fn run(
553553
.with_suggestion(|| {
554554
format!(
555555
"try `cross +{}` instead",
556-
Toolchain {
557-
host: None,
558-
..picked_toolchain
559-
}
556+
picked_toolchain.remove_host()
560557
)
561558
}).with_section(|| format!(
562559
r#"Overriding the toolchain in cross is only possible in CLI by specifying a channel and optional date: `+channel[-YYYY-MM-DD]`.
@@ -574,7 +571,8 @@ To override the toolchain mounted in the image, set `target.{}.image.toolchain =
574571
let image = image.to_definite_with(&engine, msg_info);
575572

576573
toolchain.replace_host(&image.platform);
577-
let maybe_warn = matches!(toolchain.channel.as_str(), "stable" | "beta" | "nightly");
574+
let picked_generic_channel =
575+
matches!(toolchain.channel.as_str(), "stable" | "beta" | "nightly");
578576

579577
if image.platform.target.is_supported(Some(&target)) {
580578
if image.platform.architecture != toolchain.host().architecture {
@@ -593,7 +591,9 @@ To override the toolchain mounted in the image, set `target.{}.image.toolchain =
593591
rustup::install_toolchain(&toolchain, msg_info)?;
594592
}
595593
let available_targets = if !toolchain.is_custom {
596-
rustup::available_targets(&toolchain.full, msg_info)?
594+
rustup::available_targets(&toolchain.full, msg_info).with_note(|| {
595+
format!("cross would use the toolchain '{toolchain}' for mounting rust")
596+
})?
597597
} else {
598598
rustup::AvailableTargets {
599599
default: String::new(),
@@ -604,7 +604,7 @@ To override the toolchain mounted in the image, set `target.{}.image.toolchain =
604604

605605
let mut rustc_version = None;
606606
if let Some((version, channel, commit)) = toolchain.rustc_version()? {
607-
if maybe_warn && toolchain.date.is_none() {
607+
if picked_generic_channel && toolchain.date.is_none() {
608608
warn_host_version_mismatch(
609609
&host_version_meta,
610610
&toolchain,

src/rustc.rs

+13
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,19 @@ pub struct Toolchain {
284284
pub full: String,
285285
}
286286

287+
impl Toolchain {
288+
pub fn remove_host(&self) -> Self {
289+
let mut new = Self {
290+
host: None,
291+
..self.clone()
292+
};
293+
if let Some(host) = &self.host {
294+
new.full = new.full.replace(&format!("-{host}"), "");
295+
}
296+
new
297+
}
298+
}
299+
287300
impl std::fmt::Display for Toolchain {
288301
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
289302
f.write_str(&self.full)

src/rustup.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::path::PathBuf;
22
use std::process::Command;
33

4-
use color_eyre::owo_colors::OwoColorize;
5-
use color_eyre::SectionExt;
64
use rustc_version::{Channel, Version};
75

86
use crate::errors::*;
@@ -93,14 +91,22 @@ pub fn available_targets(
9391
.suggestion("is rustup installed?")?;
9492

9593
if !output.status.success() {
96-
if String::from_utf8_lossy(&output.stderr).contains("is a custom toolchain") {
97-
return Err(eyre::eyre!("`{toolchain}` is a custom toolchain.").with_section(|| r#"To use this toolchain with cross, you'll need to set the environment variable `CROSS_CUSTOM_TOOLCHAIN=1`
98-
cross will not attempt to configure the toolchain further so that it can run your binary."#.header("Suggestion".bright_cyan())));
99-
}
100-
return Err(cmd
94+
let mut err = cmd
10195
.status_result(msg_info, output.status, Some(&output))
10296
.expect_err("we know the command failed")
103-
.to_section_report());
97+
.to_section_report();
98+
if String::from_utf8_lossy(&output.stderr).contains("is a custom toolchain") {
99+
err = err.wrap_err("'{toolchain}' is a custom toolchain.")
100+
.suggestion(r#"To use this toolchain with cross, you'll need to set the environment variable `CROSS_CUSTOM_TOOLCHAIN=1`
101+
cross will not attempt to configure the toolchain further so that it can run your binary."#);
102+
} else if String::from_utf8_lossy(&output.stderr).contains("does not support components") {
103+
err = err.suggestion(format!(
104+
"try reinstalling the '{toolchain}' toolchain
105+
$ rustup toolchain uninstall {toolchain}
106+
$ rustup toolchain install {toolchain} --force-non-host"
107+
));
108+
}
109+
return Err(err);
104110
}
105111
let out = output.stdout()?;
106112
let mut default = String::new();

0 commit comments

Comments
 (0)