Merge pull request #23743 from stangri/master-nghttp3
[feed/packages.git] / lang / rust / patches / 0002-rustc-bootstrap-cache.patch
1 --- a/src/bootstrap/bootstrap.py
2 +++ b/src/bootstrap/bootstrap.py
3 @@ -557,7 +557,7 @@ class RustBuild(object):
4 shutil.rmtree(bin_root)
5
6 key = self.stage0_compiler.date
7 - cache_dst = os.path.join(self.build_dir, "cache")
8 + cache_dst = os.getenv('OPENWRT_RUSTC_BOOTSTRAP_CACHE', os.path.join(self.build_dir, "cache"))
9 rustc_cache = os.path.join(cache_dst, key)
10 if not os.path.exists(rustc_cache):
11 os.makedirs(rustc_cache)
12 --- a/src/bootstrap/src/core/download.rs
13 +++ b/src/bootstrap/src/core/download.rs
14 @@ -208,10 +208,13 @@ impl Config {
15 Some(other) => panic!("unsupported protocol {other} in {url}"),
16 None => panic!("no protocol in {url}"),
17 }
18 - t!(
19 - std::fs::rename(&tempfile, dest_path),
20 - format!("failed to rename {tempfile:?} to {dest_path:?}")
21 - );
22 + match std::fs::rename(&tempfile, dest_path) {
23 + Ok(v) => v,
24 + Err(_) => {
25 + t!(std::fs::copy(&tempfile, dest_path));
26 + t!(std::fs::remove_file(&tempfile));
27 + }
28 + };
29 }
30
31 fn download_http_with_retries(&self, tempfile: &Path, url: &str, help_on_error: &str) {
32 @@ -577,7 +580,10 @@ impl Config {
33 return;
34 }
35
36 - let cache_dst = self.out.join("cache");
37 + let cache_dst = match env::var_os("OPENWRT_RUSTC_BOOTSTRAP_CACHE") {
38 + Some(v) => PathBuf::from(v),
39 + None => self.out.join("cache"),
40 + };
41 let cache_dir = cache_dst.join(key);
42 if !cache_dir.exists() {
43 t!(fs::create_dir_all(&cache_dir));
44 @@ -704,7 +710,10 @@ download-rustc = false
45 let llvm_assertions = self.llvm_assertions;
46
47 let cache_prefix = format!("llvm-{llvm_sha}-{llvm_assertions}");
48 - let cache_dst = self.out.join("cache");
49 + let cache_dst = match env::var_os("OPENWRT_RUSTC_BOOTSTRAP_CACHE") {
50 + Some(v) => PathBuf::from(v),
51 + None => self.out.join("cache"),
52 + };
53 let rustc_cache = cache_dst.join(cache_prefix);
54 if !rustc_cache.exists() {
55 t!(fs::create_dir_all(&rustc_cache));