Skip to content

Commit d4eb9d1

Browse files
authored
Unrolled build for rust-lang#136962
Rollup merge of rust-lang#136962 - onur-ozkan:fix-enzyme-note, r=jieyouxu unify LLVM version finding logic kind a self-explanatory
2 parents a567209 + 0709ba3 commit d4eb9d1

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1092,9 +1092,10 @@ pub fn rustc_cargo(
10921092

10931093
// We want to link against registerEnzyme and in the future we want to use additional
10941094
// functionality from Enzyme core. For that we need to link against Enzyme.
1095-
// FIXME(ZuseZ4): Get the LLVM version number automatically instead of hardcoding it.
10961095
if builder.config.llvm_enzyme {
1097-
cargo.rustflag("-l").rustflag("Enzyme-19");
1096+
let llvm_config = builder.llvm_config(builder.config.build).unwrap();
1097+
let llvm_version_major = llvm::get_llvm_version_major(builder, &llvm_config);
1098+
cargo.rustflag("-l").rustflag(&format!("Enzyme-{llvm_version_major}"));
10981099
}
10991100

11001101
// Building with protected visibility reduces the number of dynamic relocations needed, giving

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

+12-5
Original file line numberDiff line numberDiff line change
@@ -571,10 +571,7 @@ impl Step for Llvm {
571571

572572
// Helper to find the name of LLVM's shared library on darwin and linux.
573573
let find_llvm_lib_name = |extension| {
574-
let version =
575-
command(&res.llvm_config).arg("--version").run_capture_stdout(builder).stdout();
576-
let major = version.split('.').next().unwrap();
577-
574+
let major = get_llvm_version_major(builder, &res.llvm_config);
578575
match &llvm_version_suffix {
579576
Some(version_suffix) => format!("libLLVM-{major}{version_suffix}.{extension}"),
580577
None => format!("libLLVM-{major}.{extension}"),
@@ -624,12 +621,22 @@ impl Step for Llvm {
624621
}
625622
}
626623

624+
pub fn get_llvm_version(builder: &Builder<'_>, llvm_config: &Path) -> String {
625+
command(llvm_config).arg("--version").run_capture_stdout(builder).stdout().trim().to_owned()
626+
}
627+
628+
pub fn get_llvm_version_major(builder: &Builder<'_>, llvm_config: &Path) -> u8 {
629+
let version = get_llvm_version(builder, llvm_config);
630+
let major_str = version.split_once('.').expect("Failed to parse LLVM version").0;
631+
major_str.parse().unwrap()
632+
}
633+
627634
fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) {
628635
if builder.config.dry_run() {
629636
return;
630637
}
631638

632-
let version = command(llvm_config).arg("--version").run_capture_stdout(builder).stdout();
639+
let version = get_llvm_version(builder, llvm_config);
633640
let mut parts = version.split('.').take(2).filter_map(|s| s.parse::<u32>().ok());
634641
if let (Some(major), Some(_minor)) = (parts.next(), parts.next()) {
635642
if major >= 18 {

src/bootstrap/src/core/build_steps/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use clap_complete::shells;
1212

1313
use crate::core::build_steps::compile::run_cargo;
1414
use crate::core::build_steps::doc::DocumentationFormat;
15+
use crate::core::build_steps::llvm::get_llvm_version;
1516
use crate::core::build_steps::synthetic_targets::MirOptPanicAbortSyntheticTarget;
1617
use crate::core::build_steps::tool::{self, SourceType, Tool};
1718
use crate::core::build_steps::toolstate::ToolState;
@@ -1945,8 +1946,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
19451946
let llvm::LlvmResult { llvm_config, .. } =
19461947
builder.ensure(llvm::Llvm { target: builder.config.build });
19471948
if !builder.config.dry_run() {
1948-
let llvm_version =
1949-
command(&llvm_config).arg("--version").run_capture_stdout(builder).stdout();
1949+
let llvm_version = get_llvm_version(builder, &llvm_config);
19501950
let llvm_components =
19511951
command(&llvm_config).arg("--components").run_capture_stdout(builder).stdout();
19521952
// Remove trailing newline from llvm-config output.

src/bootstrap/src/core/builder/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ impl<'a> Builder<'a> {
14311431
///
14321432
/// Note that this returns `None` if LLVM is disabled, or if we're in a
14331433
/// check build or dry-run, where there's no need to build all of LLVM.
1434-
fn llvm_config(&self, target: TargetSelection) -> Option<PathBuf> {
1434+
pub fn llvm_config(&self, target: TargetSelection) -> Option<PathBuf> {
14351435
if self.config.llvm_enabled(target) && self.kind != Kind::Check && !self.config.dry_run() {
14361436
let llvm::LlvmResult { llvm_config, .. } = self.ensure(llvm::Llvm { target });
14371437
if llvm_config.is_file() {

0 commit comments

Comments
 (0)