Skip to content

Commit

Permalink
Fixes custom toolchain support without rustup.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Alexhuszagh committed Oct 19, 2022
1 parent ac7fbe8 commit 1d0292b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .changes/1085.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "added",
"description": "support custom toolchains without rustup."
}
1 change: 1 addition & 0 deletions src/docker/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,7 @@ mod tests {
&None,
&image_platform,
&sysroot,
false,
))
}

Expand Down
9 changes: 4 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,10 @@ To override the toolchain mounted in the image, set `target.{}.image.toolchain =
// set the sysroot explicitly to the toolchain
let mut is_nightly = toolchain.channel.contains("nightly");

let installed_toolchains = rustup::installed_toolchains(msg_info)?;

if !installed_toolchains
.into_iter()
.any(|t| t == toolchain.to_string())
if !toolchain.is_custom
&& !rustup::installed_toolchains(msg_info)?
.into_iter()
.any(|t| t == toolchain.to_string())
{
rustup::install_toolchain(&toolchain, msg_info)?;
}
Expand Down
25 changes: 19 additions & 6 deletions src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,35 @@ pub struct QualifiedToolchain {
}

impl QualifiedToolchain {
pub fn new(channel: &str, date: &Option<String>, host: &ImagePlatform, sysroot: &Path) -> Self {
pub fn new(
channel: &str,
date: &Option<String>,
host: &ImagePlatform,
sysroot: &Path,
is_custom: bool,
) -> Self {
let mut this = Self {
channel: channel.to_owned(),
date: date.clone(),
host: host.clone(),
is_custom: false,
is_custom,
full: if let Some(date) = date {
format!("{}-{}-{}", channel, date, host.target)
} else {
format!("{}-{}", channel, host.target)
},
sysroot: sysroot.to_owned(),
};
this.sysroot.set_file_name(&this.full);
if !is_custom {
this.sysroot.set_file_name(&this.full);
}
this
}

/// Replace the host, does nothing if ran on a custom toolchain
pub fn replace_host(&mut self, host: &ImagePlatform) -> &mut Self {
if !self.is_custom {
*self = Self::new(&self.channel, &self.date, host, &self.sysroot);
*self = Self::new(&self.channel, &self.date, host, &self.sysroot, false);
self.sysroot.set_file_name(&self.full);
}
self
Expand Down Expand Up @@ -168,8 +176,8 @@ impl QualifiedToolchain {
&build_date,
&ImagePlatform::from_target(host.into())?,
sysroot,
true,
);
toolchain.is_custom = true;
toolchain.full = name.to_owned();
return Ok(toolchain);
}
Expand Down Expand Up @@ -217,6 +225,7 @@ impl QualifiedToolchain {
&date,
&host,
&self.sysroot,
false,
))
}

Expand Down Expand Up @@ -256,7 +265,11 @@ impl QualifiedToolchain {
Ok(_) | Err(_) if config.custom_toolchain() => {
QualifiedToolchain::custom(toolchain, &sysroot, config, msg_info)
}
Ok(_) => eyre::bail!("toolchain is not fully qualified"),
Ok(_) => return Err(eyre::eyre!("toolchain is not fully qualified")
.with_note(|| "cross expects the toolchain to be a rustup installed toolchain")
.with_suggestion(|| {
"if you're using a custom toolchain try setting `CROSS_CUSTOM_TOOLCHAIN=1` or install rust via rustup"
})),
Err(e) => Err(e),
}
}
Expand Down
1 change: 1 addition & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ release: {version}
&None,
&ImagePlatform::from_const_target(TargetTriple::X86_64UnknownLinuxGnu),
Path::new("/toolchains/xxxx-x86_64-unknown-linux-gnu"),
false,
),
&target_meta.0,
&target_meta.1,
Expand Down

0 comments on commit 1d0292b

Please sign in to comment.