From 4f1cf0b5dad1ae8d791b33e9112ed8c4cb61788a Mon Sep 17 00:00:00 2001 From: Zalathar Date: Mon, 27 Nov 2023 17:39:34 +1100 Subject: [PATCH] bootstrap: Memoize the LLVM rebuild hash to avoid very slow `x check` --- src/bootstrap/src/core/build_steps/llvm.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index f710c01ca33cc..f014ef51c75c2 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -15,6 +15,7 @@ use std::fs::{self, File}; use std::io; use std::path::{Path, PathBuf}; use std::process::Command; +use std::sync::OnceLock; use crate::core::builder::{Builder, RunConfig, ShouldRun, Step}; use crate::core::config::{Config, TargetSelection}; @@ -105,13 +106,16 @@ pub fn prebuilt_llvm_config( let llvm_cmake_dir = out_dir.join("lib/cmake/llvm"); let res = LlvmResult { llvm_config: build_llvm_config, llvm_cmake_dir }; - let smart_stamp_hash = generate_smart_stamp_hash( - &builder.config.src.join("src/llvm-project"), - &builder.in_tree_llvm_info.sha().unwrap_or_default(), - ); + static STAMP_HASH_MEMO: OnceLock = OnceLock::new(); + let smart_stamp_hash = STAMP_HASH_MEMO.get_or_init(|| { + generate_smart_stamp_hash( + &builder.config.src.join("src/llvm-project"), + &builder.in_tree_llvm_info.sha().unwrap_or_default(), + ) + }); let stamp = out_dir.join("llvm-finished-building"); - let stamp = HashStamp::new(stamp, Some(&smart_stamp_hash)); + let stamp = HashStamp::new(stamp, Some(smart_stamp_hash)); if stamp.is_done() { if stamp.hash.is_none() {