Skip to content

Commit 9c05758

Browse files
committed
Remove duplicated check for LLVM modifications and disable download-ci-llvm=true on CI
1 parent 80a5adf commit 9c05758

File tree

3 files changed

+23
-42
lines changed

3 files changed

+23
-42
lines changed

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

+3-37
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::path::{Path, PathBuf};
1414
use std::sync::OnceLock;
1515
use std::{env, fs};
1616

17-
use build_helper::ci::CiEnv;
1817
use build_helper::git::get_closest_merge_commit;
1918
#[cfg(feature = "tracing")]
2019
use tracing::instrument;
@@ -206,10 +205,9 @@ pub(crate) fn detect_llvm_sha(config: &Config, is_git: bool) -> String {
206205

207206
/// Returns whether the CI-found LLVM is currently usable.
208207
///
209-
/// This checks both the build triple platform to confirm we're usable at all,
210-
/// and then verifies if the current HEAD matches the detected LLVM SHA head,
211-
/// in which case LLVM is indicated as not available.
212-
pub(crate) fn is_ci_llvm_available(config: &Config, asserts: bool) -> bool {
208+
/// This checks the build triple platform to confirm we're usable at all, and if LLVM
209+
/// with/without assertions is available.
210+
pub(crate) fn is_ci_llvm_available_for_target(config: &Config, asserts: bool) -> bool {
213211
// This is currently all tier 1 targets and tier 2 targets with host tools
214212
// (since others may not have CI artifacts)
215213
// https://doc.rust-lang.org/rustc/platform-support.html#tier-1
@@ -254,41 +252,9 @@ pub(crate) fn is_ci_llvm_available(config: &Config, asserts: bool) -> bool {
254252
return false;
255253
}
256254

257-
if is_ci_llvm_modified(config) {
258-
eprintln!("Detected LLVM as non-available: running in CI and modified LLVM in this change");
259-
return false;
260-
}
261-
262255
true
263256
}
264257

265-
/// Returns true if we're running in CI with modified LLVM (and thus can't download it)
266-
pub(crate) fn is_ci_llvm_modified(config: &Config) -> bool {
267-
// If not running in a CI environment, return false.
268-
if !config.is_running_on_ci {
269-
return false;
270-
}
271-
272-
// In rust-lang/rust managed CI, assert the existence of the LLVM submodule.
273-
if CiEnv::is_rust_lang_managed_ci_job() {
274-
assert!(
275-
config.in_tree_llvm_info.is_managed_git_subrepository(),
276-
"LLVM submodule must be fetched in rust-lang/rust managed CI builders."
277-
);
278-
}
279-
// If LLVM submodule isn't present, skip the change check as it won't work.
280-
else if !config.in_tree_llvm_info.is_managed_git_subrepository() {
281-
return false;
282-
}
283-
284-
let llvm_sha = detect_llvm_sha(config, true);
285-
let head_sha = crate::output(
286-
helpers::git(Some(&config.src)).arg("rev-parse").arg("HEAD").as_command_mut(),
287-
);
288-
let head_sha = head_sha.trim();
289-
llvm_sha == head_sha
290-
}
291-
292258
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
293259
pub struct Llvm {
294260
pub target: TargetSelection,

Diff for: src/bootstrap/src/core/config/config.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -3116,7 +3116,7 @@ impl Config {
31163116
.is_none();
31173117

31183118
// Return false if there are untracked changes, otherwise check if CI LLVM is available.
3119-
if has_changes { false } else { llvm::is_ci_llvm_available(self, asserts) }
3119+
if has_changes { false } else { llvm::is_ci_llvm_available_for_target(self, asserts) }
31203120
};
31213121

31223122
match download_ci_llvm {
@@ -3127,8 +3127,15 @@ impl Config {
31273127
);
31283128
}
31293129

3130+
if b && self.is_running_on_ci {
3131+
// On CI, we must always rebuild LLVM if there were any modifications to it
3132+
panic!(
3133+
"`llvm.download-ci-llvm` cannot be set to `true` on CI. Use `if-unchanged` instead."
3134+
);
3135+
}
3136+
31303137
// If download-ci-llvm=true we also want to check that CI llvm is available
3131-
b && llvm::is_ci_llvm_available(self, asserts)
3138+
b && llvm::is_ci_llvm_available_for_target(self, asserts)
31323139
}
31333140
StringOrBool::String(s) if s == "if-unchanged" => if_unchanged(),
31343141
StringOrBool::String(other) => {

Diff for: src/bootstrap/src/core/config/tests.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,21 @@ pub(crate) fn parse(config: &str) -> Config {
2525
#[test]
2626
fn download_ci_llvm() {
2727
let config = parse("");
28-
let is_available = llvm::is_ci_llvm_available(&config, config.llvm_assertions);
28+
let is_available = llvm::is_ci_llvm_available_for_target(&config, config.llvm_assertions);
2929
if is_available {
3030
assert!(config.llvm_from_ci);
3131
}
3232

33-
let config = parse("llvm.download-ci-llvm = true");
34-
let is_available = llvm::is_ci_llvm_available(&config, config.llvm_assertions);
33+
let config = Config::parse_inner(
34+
Flags::parse(&[
35+
"check".to_string(),
36+
"--config=/does/not/exist".to_string(),
37+
"--ci".to_string(),
38+
"false".to_string(),
39+
]),
40+
|&_| toml::from_str("llvm.download-ci-llvm = true"),
41+
);
42+
let is_available = llvm::is_ci_llvm_available_for_target(&config, config.llvm_assertions);
3543
if is_available {
3644
assert!(config.llvm_from_ci);
3745
}

0 commit comments

Comments
 (0)