Skip to content

Commit b9643b0

Browse files
committed
Remove duplicated check for LLVM modifications and disable download-ci-llvm=true on CI
1 parent 7386cab commit b9643b0

File tree

3 files changed

+21
-44
lines changed

3 files changed

+21
-44
lines changed

src/bootstrap/src/core/build_steps/llvm.rs

Lines changed: 3 additions & 37 deletions
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 !CiEnv::is_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,

src/bootstrap/src/core/config/config.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3113,7 +3113,7 @@ impl Config {
31133113
.is_none();
31143114

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

31193119
match download_ci_llvm {
@@ -3124,8 +3124,15 @@ impl Config {
31243124
);
31253125
}
31263126

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

src/bootstrap/src/core/config/tests.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::fs::{File, remove_file};
44
use std::io::Write;
55
use std::path::Path;
66

7+
use build_helper::ci::CiEnv;
78
use clap::CommandFactory;
89
use serde::Deserialize;
910

@@ -24,15 +25,18 @@ pub(crate) fn parse(config: &str) -> Config {
2425
#[test]
2526
fn download_ci_llvm() {
2627
let config = parse("");
27-
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);
2829
if is_available {
2930
assert!(config.llvm_from_ci);
3031
}
3132

32-
let config = parse("llvm.download-ci-llvm = true");
33-
let is_available = llvm::is_ci_llvm_available(&config, config.llvm_assertions);
34-
if is_available {
35-
assert!(config.llvm_from_ci);
33+
// download-ci-llvm=true is not supported on CI
34+
if !CiEnv::is_ci() {
35+
let config = parse("llvm.download-ci-llvm = true");
36+
let is_available = llvm::is_ci_llvm_available_for_target(&config, config.llvm_assertions);
37+
if is_available {
38+
assert!(config.llvm_from_ci);
39+
}
3640
}
3741

3842
let config = parse("llvm.download-ci-llvm = false");

0 commit comments

Comments
 (0)