Skip to content

Commit

Permalink
Unrolled build for rust-lang#118187
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
rust-timer committed Nov 24, 2023
2 parents 4fd68eb + 111ad61 commit 0156fa1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::core::config::{Config, TargetSelection};
use crate::utils::channel;
use crate::utils::helpers::{self, exe, get_clang_cl_resource_dir, output, t, up_to_date};
use crate::{CLang, GitRepo, Kind};
use crate::{generate_smart_stamp_hash, CLang, GitRepo, Kind};

use build_helper::ci::CiEnv;
use build_helper::git::get_git_merge_base;
Expand Down Expand Up @@ -105,8 +105,13 @@ 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(),
);

let stamp = out_dir.join("llvm-finished-building");
let stamp = HashStamp::new(stamp, builder.in_tree_llvm_info.sha());
let stamp = HashStamp::new(stamp, Some(&smart_stamp_hash));

if stamp.is_done() {
if stamp.hash.is_none() {
Expand Down
43 changes: 43 additions & 0 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use build_helper::exit;
use build_helper::util::fail;
use filetime::FileTime;
use once_cell::sync::OnceCell;
use sha2::digest::Digest;
use termcolor::{ColorChoice, StandardStream, WriteColor};
use utils::channel::GitInfo;

Expand Down Expand Up @@ -1918,3 +1919,45 @@ pub fn find_recent_config_change_ids(current_id: usize) -> Vec<ChangeInfo> {
.cloned()
.collect()
}

/// Computes a hash representing the state of a repository/submodule and additional input.
///
/// It uses `git diff` for the actual changes, and `git status` for including the untracked
/// files in the specified directory. The additional input is also incorporated into the
/// computation of the hash.
///
/// # Parameters
///
/// - `dir`: A reference to the directory path of the target repository/submodule.
/// - `additional_input`: An additional input to be included in the hash.
///
/// # Panics
///
/// In case of errors during `git` command execution (e.g., in tarball sources), default values
/// are used to prevent panics.
pub fn generate_smart_stamp_hash(dir: &Path, additional_input: &str) -> String {
let diff = Command::new("git")
.current_dir(dir)
.arg("diff")
.output()
.map(|o| String::from_utf8(o.stdout).unwrap_or_default())
.unwrap_or_default();

let status = Command::new("git")
.current_dir(dir)
.arg("status")
.arg("--porcelain")
.arg("-z")
.arg("--untracked-files=normal")
.output()
.map(|o| String::from_utf8(o.stdout).unwrap_or_default())
.unwrap_or_default();

let mut hasher = sha2::Sha256::new();

hasher.update(diff);
hasher.update(status);
hasher.update(additional_input);

hex::encode(hasher.finalize().as_slice())
}

0 comments on commit 0156fa1

Please sign in to comment.