Skip to content

Commit cdb2284

Browse files
Merge #1085
1085: Fixes custom toolchain support without rustup. r=Emilgardis a=Alexhuszagh Avoids checking for installed toolchains, and also prevents renaming the sysroot based on the toolchain full name, since this may be in a directory completely different than the target name. Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
2 parents 55c21b9 + 1d0292b commit cdb2284

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

.changes/1085.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "added",
3+
"description": "support custom toolchains without rustup."
4+
}

src/docker/shared.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,7 @@ mod tests {
16351635
&None,
16361636
&image_platform,
16371637
&sysroot,
1638+
false,
16381639
))
16391640
}
16401641

src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,10 @@ To override the toolchain mounted in the image, set `target.{}.image.toolchain =
578578
// set the sysroot explicitly to the toolchain
579579
let mut is_nightly = toolchain.channel.contains("nightly");
580580

581-
let installed_toolchains = rustup::installed_toolchains(msg_info)?;
582-
583-
if !installed_toolchains
584-
.into_iter()
585-
.any(|t| t == toolchain.to_string())
581+
if !toolchain.is_custom
582+
&& !rustup::installed_toolchains(msg_info)?
583+
.into_iter()
584+
.any(|t| t == toolchain.to_string())
586585
{
587586
rustup::install_toolchain(&toolchain, msg_info)?;
588587
}

src/rustc.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,35 @@ pub struct QualifiedToolchain {
9292
}
9393

9494
impl QualifiedToolchain {
95-
pub fn new(channel: &str, date: &Option<String>, host: &ImagePlatform, sysroot: &Path) -> Self {
95+
pub fn new(
96+
channel: &str,
97+
date: &Option<String>,
98+
host: &ImagePlatform,
99+
sysroot: &Path,
100+
is_custom: bool,
101+
) -> Self {
96102
let mut this = Self {
97103
channel: channel.to_owned(),
98104
date: date.clone(),
99105
host: host.clone(),
100-
is_custom: false,
106+
is_custom,
101107
full: if let Some(date) = date {
102108
format!("{}-{}-{}", channel, date, host.target)
103109
} else {
104110
format!("{}-{}", channel, host.target)
105111
},
106112
sysroot: sysroot.to_owned(),
107113
};
108-
this.sysroot.set_file_name(&this.full);
114+
if !is_custom {
115+
this.sysroot.set_file_name(&this.full);
116+
}
109117
this
110118
}
111119

112120
/// Replace the host, does nothing if ran on a custom toolchain
113121
pub fn replace_host(&mut self, host: &ImagePlatform) -> &mut Self {
114122
if !self.is_custom {
115-
*self = Self::new(&self.channel, &self.date, host, &self.sysroot);
123+
*self = Self::new(&self.channel, &self.date, host, &self.sysroot, false);
116124
self.sysroot.set_file_name(&self.full);
117125
}
118126
self
@@ -168,8 +176,8 @@ impl QualifiedToolchain {
168176
&build_date,
169177
&ImagePlatform::from_target(host.into())?,
170178
sysroot,
179+
true,
171180
);
172-
toolchain.is_custom = true;
173181
toolchain.full = name.to_owned();
174182
return Ok(toolchain);
175183
}
@@ -217,6 +225,7 @@ impl QualifiedToolchain {
217225
&date,
218226
&host,
219227
&self.sysroot,
228+
false,
220229
))
221230
}
222231

@@ -256,7 +265,11 @@ impl QualifiedToolchain {
256265
Ok(_) | Err(_) if config.custom_toolchain() => {
257266
QualifiedToolchain::custom(toolchain, &sysroot, config, msg_info)
258267
}
259-
Ok(_) => eyre::bail!("toolchain is not fully qualified"),
268+
Ok(_) => return Err(eyre::eyre!("toolchain is not fully qualified")
269+
.with_note(|| "cross expects the toolchain to be a rustup installed toolchain")
270+
.with_suggestion(|| {
271+
"if you're using a custom toolchain try setting `CROSS_CUSTOM_TOOLCHAIN=1` or install rust via rustup"
272+
})),
260273
Err(e) => Err(e),
261274
}
262275
}

src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ release: {version}
8686
&None,
8787
&ImagePlatform::from_const_target(TargetTriple::X86_64UnknownLinuxGnu),
8888
Path::new("/toolchains/xxxx-x86_64-unknown-linux-gnu"),
89+
false,
8990
),
9091
&target_meta.0,
9192
&target_meta.1,

0 commit comments

Comments
 (0)