Skip to content

Commit

Permalink
Add retries to windows-msvc-sysroot download
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Dec 22, 2024
1 parent 2d90917 commit b47c393
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/compiler/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ impl Clang {
Ok(download_url)
}

fn download_msvc_sysroot(
fn download_msvc_sysroot_once(
&self,
cache_dir: &Path,
agent: ureq::Agent,
agent: &ureq::Agent,
download_url: &str,
) -> Result<()> {
use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle};
Expand Down Expand Up @@ -194,6 +194,41 @@ impl Clang {
Ok(())
}

fn download_msvc_sysroot(
&self,
cache_dir: &Path,
agent: ureq::Agent,
download_url: &str,
) -> Result<()> {
use std::time::Duration;

const MAX_RETRIES: u32 = 3;
let mut retry_count = 0;
let mut last_error = None;

while retry_count < MAX_RETRIES {
if retry_count > 0 {
let wait_time = Duration::from_secs(2u64.pow(retry_count - 1));
std::thread::sleep(wait_time);
eprintln!(
"Retrying download (attempt {}/{})",
retry_count + 1,
MAX_RETRIES
);
}

match self.download_msvc_sysroot_once(cache_dir, &agent, download_url) {
Ok(()) => return Ok(()),
Err(e) => {
last_error = Some(e);
retry_count += 1;
}
}
}

Err(last_error.unwrap_or_else(|| anyhow::anyhow!("Failed to download MSVC sysroot")))
}

fn setup_cmake_toolchain(
&self,
target: &str,
Expand Down

0 comments on commit b47c393

Please sign in to comment.