Skip to content

Commit 0156fa1

Browse files
authored
Unrolled build for rust-lang#118187
Rollup merge of rust-lang#118187 - onur-ozkan:recompile-llvm-on-changes, r=clubby789 Recompile LLVM when it changes in the git sources Utilize a smart hash for 'llvm-finished-building' to enable recompilation of LLVM with each change in the git sources. Each change generates a unique hash value in 'llvm-finished-building', which ensures LLVM compilations only triggered with further changes. Resolves rust-lang#111893 cc `@rust-lang/wg-llvm`
2 parents 4fd68eb + 111ad61 commit 0156fa1

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

Diff for: src/bootstrap/src/core/build_steps/llvm.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
2020
use crate::core::config::{Config, TargetSelection};
2121
use crate::utils::channel;
2222
use crate::utils::helpers::{self, exe, get_clang_cl_resource_dir, output, t, up_to_date};
23-
use crate::{CLang, GitRepo, Kind};
23+
use crate::{generate_smart_stamp_hash, CLang, GitRepo, Kind};
2424

2525
use build_helper::ci::CiEnv;
2626
use build_helper::git::get_git_merge_base;
@@ -105,8 +105,13 @@ pub fn prebuilt_llvm_config(
105105
let llvm_cmake_dir = out_dir.join("lib/cmake/llvm");
106106
let res = LlvmResult { llvm_config: build_llvm_config, llvm_cmake_dir };
107107

108+
let smart_stamp_hash = generate_smart_stamp_hash(
109+
&builder.config.src.join("src/llvm-project"),
110+
&builder.in_tree_llvm_info.sha().unwrap_or_default(),
111+
);
112+
108113
let stamp = out_dir.join("llvm-finished-building");
109-
let stamp = HashStamp::new(stamp, builder.in_tree_llvm_info.sha());
114+
let stamp = HashStamp::new(stamp, Some(&smart_stamp_hash));
110115

111116
if stamp.is_done() {
112117
if stamp.hash.is_none() {

Diff for: src/bootstrap/src/lib.rs

+43
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use build_helper::exit;
3131
use build_helper::util::fail;
3232
use filetime::FileTime;
3333
use once_cell::sync::OnceCell;
34+
use sha2::digest::Digest;
3435
use termcolor::{ColorChoice, StandardStream, WriteColor};
3536
use utils::channel::GitInfo;
3637

@@ -1918,3 +1919,45 @@ pub fn find_recent_config_change_ids(current_id: usize) -> Vec<ChangeInfo> {
19181919
.cloned()
19191920
.collect()
19201921
}
1922+
1923+
/// Computes a hash representing the state of a repository/submodule and additional input.
1924+
///
1925+
/// It uses `git diff` for the actual changes, and `git status` for including the untracked
1926+
/// files in the specified directory. The additional input is also incorporated into the
1927+
/// computation of the hash.
1928+
///
1929+
/// # Parameters
1930+
///
1931+
/// - `dir`: A reference to the directory path of the target repository/submodule.
1932+
/// - `additional_input`: An additional input to be included in the hash.
1933+
///
1934+
/// # Panics
1935+
///
1936+
/// In case of errors during `git` command execution (e.g., in tarball sources), default values
1937+
/// are used to prevent panics.
1938+
pub fn generate_smart_stamp_hash(dir: &Path, additional_input: &str) -> String {
1939+
let diff = Command::new("git")
1940+
.current_dir(dir)
1941+
.arg("diff")
1942+
.output()
1943+
.map(|o| String::from_utf8(o.stdout).unwrap_or_default())
1944+
.unwrap_or_default();
1945+
1946+
let status = Command::new("git")
1947+
.current_dir(dir)
1948+
.arg("status")
1949+
.arg("--porcelain")
1950+
.arg("-z")
1951+
.arg("--untracked-files=normal")
1952+
.output()
1953+
.map(|o| String::from_utf8(o.stdout).unwrap_or_default())
1954+
.unwrap_or_default();
1955+
1956+
let mut hasher = sha2::Sha256::new();
1957+
1958+
hasher.update(diff);
1959+
hasher.update(status);
1960+
hasher.update(additional_input);
1961+
1962+
hex::encode(hasher.finalize().as_slice())
1963+
}

0 commit comments

Comments
 (0)