Rollup merge of #136962 - onur-ozkan:fix-enzyme-note, r=jieyouxu
unify LLVM version finding logic kind a self-explanatory
This commit is contained in:
commit
0e8596077b
4 changed files with 18 additions and 10 deletions
|
@ -1092,9 +1092,10 @@ pub fn rustc_cargo(
|
|||
|
||||
// We want to link against registerEnzyme and in the future we want to use additional
|
||||
// functionality from Enzyme core. For that we need to link against Enzyme.
|
||||
// FIXME(ZuseZ4): Get the LLVM version number automatically instead of hardcoding it.
|
||||
if builder.config.llvm_enzyme {
|
||||
cargo.rustflag("-l").rustflag("Enzyme-19");
|
||||
let llvm_config = builder.llvm_config(builder.config.build).unwrap();
|
||||
let llvm_version_major = llvm::get_llvm_version_major(builder, &llvm_config);
|
||||
cargo.rustflag("-l").rustflag(&format!("Enzyme-{llvm_version_major}"));
|
||||
}
|
||||
|
||||
// Building with protected visibility reduces the number of dynamic relocations needed, giving
|
||||
|
|
|
@ -571,10 +571,7 @@ impl Step for Llvm {
|
|||
|
||||
// Helper to find the name of LLVM's shared library on darwin and linux.
|
||||
let find_llvm_lib_name = |extension| {
|
||||
let version =
|
||||
command(&res.llvm_config).arg("--version").run_capture_stdout(builder).stdout();
|
||||
let major = version.split('.').next().unwrap();
|
||||
|
||||
let major = get_llvm_version_major(builder, &res.llvm_config);
|
||||
match &llvm_version_suffix {
|
||||
Some(version_suffix) => format!("libLLVM-{major}{version_suffix}.{extension}"),
|
||||
None => format!("libLLVM-{major}.{extension}"),
|
||||
|
@ -624,12 +621,22 @@ impl Step for Llvm {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_llvm_version(builder: &Builder<'_>, llvm_config: &Path) -> String {
|
||||
command(llvm_config).arg("--version").run_capture_stdout(builder).stdout().trim().to_owned()
|
||||
}
|
||||
|
||||
pub fn get_llvm_version_major(builder: &Builder<'_>, llvm_config: &Path) -> u8 {
|
||||
let version = get_llvm_version(builder, llvm_config);
|
||||
let major_str = version.split_once('.').expect("Failed to parse LLVM version").0;
|
||||
major_str.parse().unwrap()
|
||||
}
|
||||
|
||||
fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) {
|
||||
if builder.config.dry_run() {
|
||||
return;
|
||||
}
|
||||
|
||||
let version = command(llvm_config).arg("--version").run_capture_stdout(builder).stdout();
|
||||
let version = get_llvm_version(builder, llvm_config);
|
||||
let mut parts = version.split('.').take(2).filter_map(|s| s.parse::<u32>().ok());
|
||||
if let (Some(major), Some(_minor)) = (parts.next(), parts.next()) {
|
||||
if major >= 18 {
|
||||
|
|
|
@ -12,6 +12,7 @@ use clap_complete::shells;
|
|||
|
||||
use crate::core::build_steps::compile::run_cargo;
|
||||
use crate::core::build_steps::doc::DocumentationFormat;
|
||||
use crate::core::build_steps::llvm::get_llvm_version;
|
||||
use crate::core::build_steps::synthetic_targets::MirOptPanicAbortSyntheticTarget;
|
||||
use crate::core::build_steps::tool::{self, SourceType, Tool};
|
||||
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
|
|||
let llvm::LlvmResult { llvm_config, .. } =
|
||||
builder.ensure(llvm::Llvm { target: builder.config.build });
|
||||
if !builder.config.dry_run() {
|
||||
let llvm_version =
|
||||
command(&llvm_config).arg("--version").run_capture_stdout(builder).stdout();
|
||||
let llvm_version = get_llvm_version(builder, &llvm_config);
|
||||
let llvm_components =
|
||||
command(&llvm_config).arg("--components").run_capture_stdout(builder).stdout();
|
||||
// Remove trailing newline from llvm-config output.
|
||||
|
|
|
@ -1431,7 +1431,7 @@ impl<'a> Builder<'a> {
|
|||
///
|
||||
/// Note that this returns `None` if LLVM is disabled, or if we're in a
|
||||
/// check build or dry-run, where there's no need to build all of LLVM.
|
||||
fn llvm_config(&self, target: TargetSelection) -> Option<PathBuf> {
|
||||
pub fn llvm_config(&self, target: TargetSelection) -> Option<PathBuf> {
|
||||
if self.config.llvm_enabled(target) && self.kind != Kind::Check && !self.config.dry_run() {
|
||||
let llvm::LlvmResult { llvm_config, .. } = self.ensure(llvm::Llvm { target });
|
||||
if llvm_config.is_file() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue