Skip to content

fix: Automatically install nightly toolchain when missing #2886

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub struct Config {
pub(crate) build_cpu_limit: Option<u32>,
pub(crate) build_default_memory_limit: Option<usize>,
pub(crate) include_default_targets: bool,
#[allow(dead_code)]
pub(crate) disable_memory_limit: bool,

// automatic rebuild configuration
Expand Down
26 changes: 25 additions & 1 deletion src/docbuilder/rustwide_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,34 @@ impl RustwideBuilder {
}

pub fn add_essential_files(&mut self) -> Result<()> {
// Check if toolchain is available, install if needed
match self.detect_rustc_version() {
Ok(_) => {
info!("Toolchain is already installed");
}
Err(err) => {
// Check if the error is specifically due to missing toolchain
let err_msg = err.to_string();
if err_msg.contains("No such file or directory")
|| err_msg.contains("command not found")
|| err_msg.contains("not installed")
{
info!("Installing nightly toolchain because it was not found");
self.update_toolchain()?;
} else {
// Don't try to install the toolchain if some other error occurred
return Err(anyhow!(
"Failed to detect rustc version: {}\n\nThis might indicate the nightly toolchain is not properly installed. Please run 'cratesfyi build update-toolchain' first.",
err
));
}
}
}

let rustc_version = self.rustc_version()?;
let parsed_rustc_version = parse_rustc_version(&rustc_version)?;

info!("building a dummy crate to get essential files");
info!("building a dummy crate to get essential files for {rustc_version}");

let limits = self.get_limits(DUMMY_CRATE_NAME)?;

Expand Down
Loading