Skip to content

Support auto-installing toolchain with rustup-toolchain-install-master #1025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions collector/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,41 @@ fn get_local_toolchain(
// + prefixed rustc is an indicator to fetch the rustc of the toolchain
// specified. This follows the similar pattern used by rustup's binaries
// (e.g., `rustc +stage1`).
let rustc = if rustc.starts_with('+') {
let s = String::from_utf8(
Command::new("rustup")
.args(&["which", "rustc", "--toolchain", &rustc[1..]])
.output()
let rustc = if let Some(toolchain) = rustc.strip_prefix('+') {
let output = Command::new("rustup")
.args(&["which", "rustc", "--toolchain", &toolchain])
.output()
.context("failed to run `rustup which rustc`")?;

// Looks like a commit hash? Try to install it...
if output.status.code() == Some(101) && toolchain.len() == 40 {
// No such toolchain exists, so let's try to install it with
// rustup-toolchain-install-master.

if !Command::new("rustup-toolchain-install-master")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A common failure mode here would like be not having rustup-toolchain-install-master installed. Should we specifically handle that case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we actually have sysroot building code built-in already and we should use that, I had forgotten about it when writing this.

.arg(&toolchain)
.status()
.context("failed to run `rustup which rustc`")?
.stdout,
)
.context("failed to convert `rustup which rustc` output to utf8")?;
.success()
{
anyhow::bail!(
"commit-like toolchain {} did not install successfully",
toolchain
)
}
}

let output = Command::new("rustup")
.args(&["which", "rustc", "--toolchain", &toolchain])
.output()
.context("failed to run `rustup which rustc`")?;

if !output.status.success() {
anyhow::bail!("did not manage to obtain toolchain {}", toolchain);
}

let s = String::from_utf8(output.stdout)
.context("failed to convert `rustup which rustc` output to utf8")?;

let rustc = PathBuf::from(s.trim());
debug!("found rustc: {:?}", &rustc);
Expand Down