Skip to content

Commit 2002b4b

Browse files
committed
Auto merge of #59303 - euclio:remove-rebuild-trigger, r=cuviper
replace llvm-rebuild-trigger with submodule commit hash As mentioned in #59285. This PR removes the need to update the `llvm-rebuild-trigger` file. Instead, the latest commit hash of the appropriate LLVM submodule will be stored in the stamp file and used to detect if a build is required. Fixes #42405. Fixes #54959. Fixes #55537.
2 parents 003382e + e1daa36 commit 2002b4b

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

src/bootstrap/native.rs

+33-15
Original file line numberDiff line numberDiff line change
@@ -67,30 +67,47 @@ impl Step for Llvm {
6767
}
6868
}
6969

70-
let rebuild_trigger = builder.src.join("src/rustllvm/llvm-rebuild-trigger");
71-
let rebuild_trigger_contents = t!(fs::read_to_string(&rebuild_trigger));
72-
73-
let (out_dir, llvm_config_ret_dir) = if emscripten {
70+
let (submodule, root, out_dir, llvm_config_ret_dir) = if emscripten {
7471
let dir = builder.emscripten_llvm_out(target);
7572
let config_dir = dir.join("bin");
76-
(dir, config_dir)
73+
("src/llvm-emscripten", "src/llvm-emscripten", dir, config_dir)
7774
} else {
7875
let mut dir = builder.llvm_out(builder.config.build);
7976
if !builder.config.build.contains("msvc") || builder.config.ninja {
8077
dir.push("build");
8178
}
82-
(builder.llvm_out(target), dir.join("bin"))
79+
("src/llvm-project", "src/llvm-project/llvm", builder.llvm_out(target), dir.join("bin"))
8380
};
84-
let done_stamp = out_dir.join("llvm-finished-building");
81+
82+
let git_output = t!(Command::new("git")
83+
.args(&["rev-parse", "--verify", &format!("@:./{}", submodule)])
84+
.current_dir(&builder.src)
85+
.output());
86+
87+
let llvm_commit = if git_output.status.success() {
88+
Some(git_output.stdout)
89+
} else {
90+
println!(
91+
"git could not determine the LLVM submodule commit hash ({}). \
92+
Assuming that an LLVM build is necessary.",
93+
String::from_utf8_lossy(&git_output.stderr),
94+
);
95+
None
96+
};
97+
8598
let build_llvm_config = llvm_config_ret_dir
8699
.join(exe("llvm-config", &*builder.config.build));
87-
if done_stamp.exists() {
88-
let done_contents = t!(fs::read_to_string(&done_stamp));
100+
let done_stamp = out_dir.join("llvm-finished-building");
89101

90-
// If LLVM was already built previously and contents of the rebuild-trigger file
91-
// didn't change from the previous build, then no action is required.
92-
if done_contents == rebuild_trigger_contents {
93-
return build_llvm_config
102+
if let Some(llvm_commit) = &llvm_commit {
103+
if done_stamp.exists() {
104+
let done_contents = t!(fs::read(&done_stamp));
105+
106+
// If LLVM was already built previously and the submodule's commit didn't change
107+
// from the previous build, then no action is required.
108+
if done_contents == llvm_commit.as_slice() {
109+
return build_llvm_config
110+
}
94111
}
95112
}
96113

@@ -101,7 +118,6 @@ impl Step for Llvm {
101118
t!(fs::create_dir_all(&out_dir));
102119

103120
// http://llvm.org/docs/CMake.html
104-
let root = if self.emscripten { "src/llvm-emscripten" } else { "src/llvm-project/llvm" };
105121
let mut cfg = cmake::Config::new(builder.src.join(root));
106122

107123
let profile = match (builder.config.llvm_optimize, builder.config.llvm_release_debuginfo) {
@@ -279,7 +295,9 @@ impl Step for Llvm {
279295

280296
cfg.build();
281297

282-
t!(fs::write(&done_stamp, &rebuild_trigger_contents));
298+
if let Some(llvm_commit) = llvm_commit {
299+
t!(fs::write(&done_stamp, &llvm_commit));
300+
}
283301

284302
build_llvm_config
285303
}

src/rustllvm/llvm-rebuild-trigger

-4
This file was deleted.

0 commit comments

Comments
 (0)