Skip to content

Commit d911613

Browse files
jefferytolu-zero
authored andcommitted
Allow bootstrap cache path to be set by environment variable
This allows the bootstrap cache path to be set by the `RUSTC_BOOTSTRAP_CACHE` environment variable. Setting the bootstrap cache path to an external location can help to speed up builds in cases where the build directory is not kept between builds, e.g. in CI or other automated build systems.
1 parent f7cb53e commit d911613

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/bootstrap/bootstrap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def download_toolchain(self):
557557
shutil.rmtree(bin_root)
558558

559559
key = self.stage0_compiler.date
560-
cache_dst = os.path.join(self.build_dir, "cache")
560+
cache_dst = os.getenv('RUSTC_BOOTSTRAP_CACHE', os.path.join(self.build_dir, "cache"))
561561
rustc_cache = os.path.join(cache_dst, key)
562562
if not os.path.exists(rustc_cache):
563563
os.makedirs(rustc_cache)

src/bootstrap/src/core/download.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,11 @@ impl Config {
578578
return;
579579
}
580580

581-
let cache_dst = self.out.join("cache");
581+
let cache_dst = match env::var_os("RUSTC_BOOTSTRAP_CACHE") {
582+
Some(v) => PathBuf::from(v),
583+
None => self.out.join("cache"),
584+
};
585+
582586
let cache_dir = cache_dst.join(key);
583587
if !cache_dir.exists() {
584588
t!(fs::create_dir_all(&cache_dir));
@@ -705,7 +709,10 @@ download-rustc = false
705709
let llvm_assertions = self.llvm_assertions;
706710

707711
let cache_prefix = format!("llvm-{llvm_sha}-{llvm_assertions}");
708-
let cache_dst = self.out.join("cache");
712+
let cache_dst = match env::var_os("RUSTC_BOOTSTRAP_CACHE") {
713+
Some(v) => PathBuf::from(v),
714+
None => self.out.join("cache"),
715+
};
709716
let rustc_cache = cache_dst.join(cache_prefix);
710717
if !rustc_cache.exists() {
711718
t!(fs::create_dir_all(&rustc_cache));

0 commit comments

Comments
 (0)