Skip to content

Commit d4b5d93

Browse files
byfnoelsyphar
authored andcommitted
fix: Automatically install nightly toolchain when missing
This will install the nightly toolchain automatically when we detect it missing. Fixes: 2051
1 parent 546fd47 commit d4b5d93

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ pub struct Config {
119119
pub(crate) build_cpu_limit: Option<u32>,
120120
pub(crate) build_default_memory_limit: Option<usize>,
121121
pub(crate) include_default_targets: bool,
122+
#[allow(dead_code)]
122123
pub(crate) disable_memory_limit: bool,
123124

124125
// automatic rebuild configuration

src/docbuilder/rustwide_builder.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,34 @@ impl RustwideBuilder {
299299
}
300300

301301
pub fn add_essential_files(&mut self) -> Result<()> {
302+
// Check if toolchain is available, install if needed
303+
match self.detect_rustc_version() {
304+
Ok(_) => {
305+
info!("Toolchain is already installed");
306+
}
307+
Err(err) => {
308+
// Check if the error is specifically due to missing toolchain
309+
let err_msg = err.to_string();
310+
if err_msg.contains("No such file or directory")
311+
|| err_msg.contains("command not found")
312+
|| err_msg.contains("not installed")
313+
{
314+
info!("Installing nightly toolchain because it was not found");
315+
self.update_toolchain()?;
316+
} else {
317+
// Don't try to install the toolchain if some other error occurred
318+
return Err(anyhow!(
319+
"Failed to detect rustc version: {}\n\nThis might indicate the nightly toolchain is not properly installed. Please run 'cratesfyi build update-toolchain' first.",
320+
err
321+
));
322+
}
323+
}
324+
}
325+
302326
let rustc_version = self.rustc_version()?;
303327
let parsed_rustc_version = parse_rustc_version(&rustc_version)?;
304328

305-
info!("building a dummy crate to get essential files");
329+
info!("building a dummy crate to get essential files for {rustc_version}");
306330

307331
let limits = self.get_limits(DUMMY_CRATE_NAME)?;
308332

0 commit comments

Comments
 (0)