Skip to content

Commit ce2e4da

Browse files
committed
Add a build option to specify the bootstrap cache
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 d911613 commit ce2e4da

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/bootstrap/bootstrap.py

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

559559
key = self.stage0_compiler.date
560-
cache_dst = os.getenv('RUSTC_BOOTSTRAP_CACHE', os.path.join(self.build_dir, "cache"))
560+
cache_dst = (self.get_toml('bootstrap-cache-path', 'build') or
561+
os.path.join(self.build_dir, "cache"))
562+
561563
rustc_cache = os.path.join(cache_dst, key)
562564
if not os.path.exists(rustc_cache):
563565
os.makedirs(rustc_cache)

src/bootstrap/configure.py

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def v(*args):
149149
# (others are conditionally saved).
150150
o("manage-submodules", "build.submodules", "let the build manage the git submodules")
151151
o("full-bootstrap", "build.full-bootstrap", "build three compilers instead of two (not recommended except for testing reproducible builds)")
152+
o("bootstrap-cache-path", "build.bootstrap-cache-path", "use provided path for the bootstrap cache")
152153
o("extended", "build.extended", "build an extended rust tool set")
153154

154155
v("tools", None, "List of extended tools will be installed")

src/bootstrap/src/core/config/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ pub struct Config {
161161
pub vendor: bool,
162162
pub target_config: HashMap<TargetSelection, Target>,
163163
pub full_bootstrap: bool,
164+
pub bootstrap_cache_path: Option<PathBuf>,
164165
pub extended: bool,
165166
pub tools: Option<HashSet<String>>,
166167
pub sanitizers: bool,
@@ -827,6 +828,7 @@ define_config! {
827828
locked_deps: Option<bool> = "locked-deps",
828829
vendor: Option<bool> = "vendor",
829830
full_bootstrap: Option<bool> = "full-bootstrap",
831+
bootstrap_cache_path: Option<PathBuf> = "bootstrap-cache-path",
830832
extended: Option<bool> = "extended",
831833
tools: Option<HashSet<String>> = "tools",
832834
verbose: Option<usize> = "verbose",
@@ -1389,6 +1391,7 @@ impl Config {
13891391
locked_deps,
13901392
vendor,
13911393
full_bootstrap,
1394+
bootstrap_cache_path,
13921395
extended,
13931396
tools,
13941397
verbose,
@@ -1477,6 +1480,7 @@ impl Config {
14771480
config.reuse = reuse.map(PathBuf::from);
14781481
config.submodules = submodules;
14791482
config.android_ndk = android_ndk;
1483+
config.bootstrap_cache_path = bootstrap_cache_path;
14801484
set(&mut config.low_priority, low_priority);
14811485
set(&mut config.compiler_docs, compiler_docs);
14821486
set(&mut config.library_docs_private_items, library_docs_private_items);

src/bootstrap/src/core/download.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,8 @@ impl Config {
578578
return;
579579
}
580580

581-
let cache_dst = match env::var_os("RUSTC_BOOTSTRAP_CACHE") {
582-
Some(v) => PathBuf::from(v),
583-
None => self.out.join("cache"),
584-
};
581+
let cache_dst =
582+
self.bootstrap_cache_path.as_ref().cloned().unwrap_or_else(|| self.out.join("cache"));
585583

586584
let cache_dir = cache_dst.join(key);
587585
if !cache_dir.exists() {
@@ -709,10 +707,9 @@ download-rustc = false
709707
let llvm_assertions = self.llvm_assertions;
710708

711709
let cache_prefix = format!("llvm-{llvm_sha}-{llvm_assertions}");
712-
let cache_dst = match env::var_os("RUSTC_BOOTSTRAP_CACHE") {
713-
Some(v) => PathBuf::from(v),
714-
None => self.out.join("cache"),
715-
};
710+
let cache_dst =
711+
self.bootstrap_cache_path.as_ref().cloned().unwrap_or_else(|| self.out.join("cache"));
712+
716713
let rustc_cache = cache_dst.join(cache_prefix);
717714
if !rustc_cache.exists() {
718715
t!(fs::create_dir_all(&rustc_cache));

0 commit comments

Comments
 (0)