Skip to content

Commit a4bded4

Browse files
committed
extract helper to find libLLVM's name
1 parent 7f37f6a commit a4bded4

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/bootstrap/llvm.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,19 +491,24 @@ impl Step for Llvm {
491491

492492
cfg.build();
493493

494-
// When building LLVM with LLVM_LINK_LLVM_DYLIB for macOS, an unversioned
495-
// libLLVM.dylib will be built. However, llvm-config will still look
496-
// for a versioned path like libLLVM-14.dylib. Manually create a symbolic
497-
// link to make llvm-config happy.
498-
if builder.llvm_link_shared() && target.contains("apple-darwin") {
494+
// Helper to find the name of LLVM's shared library on darwin and linux.
495+
let find_llvm_lib_name = |extension| {
499496
let mut cmd = Command::new(&res.llvm_config);
500497
let version = output(cmd.arg("--version"));
501498
let major = version.split('.').next().unwrap();
502-
let lib_name = match llvm_version_suffix {
503-
Some(s) => format!("libLLVM-{major}{s}.dylib"),
504-
None => format!("libLLVM-{major}.dylib"),
499+
let lib_name = match &llvm_version_suffix {
500+
Some(version_suffix) => format!("libLLVM-{major}{version_suffix}.{extension}"),
501+
None => format!("libLLVM-{major}.{extension}"),
505502
};
503+
lib_name
504+
};
506505

506+
// When building LLVM with LLVM_LINK_LLVM_DYLIB for macOS, an unversioned
507+
// libLLVM.dylib will be built. However, llvm-config will still look
508+
// for a versioned path like libLLVM-14.dylib. Manually create a symbolic
509+
// link to make llvm-config happy.
510+
if builder.llvm_link_shared() && target.contains("apple-darwin") {
511+
let lib_name = find_llvm_lib_name("dylib");
507512
let lib_llvm = out_dir.join("build").join("lib").join(lib_name);
508513
if !lib_llvm.exists() {
509514
t!(builder.symlink_file("libLLVM.dylib", &lib_llvm));

0 commit comments

Comments
 (0)