diff --git a/src/config.rs b/src/config.rs index 923823d52..14750a24f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -119,6 +119,7 @@ pub struct Config { pub(crate) build_cpu_limit: Option, pub(crate) build_default_memory_limit: Option, pub(crate) include_default_targets: bool, + #[allow(dead_code)] pub(crate) disable_memory_limit: bool, // automatic rebuild configuration diff --git a/src/docbuilder/rustwide_builder.rs b/src/docbuilder/rustwide_builder.rs index effb74d1f..a57ec0312 100644 --- a/src/docbuilder/rustwide_builder.rs +++ b/src/docbuilder/rustwide_builder.rs @@ -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)?;