Skip to content

Commit afb8f68

Browse files
committed
Allow building LLVM DLL with MSVC
1 parent 234c31c commit afb8f68

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

  • src/bootstrap/src/core/build_steps

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::utils::exec::command;
2424
use crate::utils::helpers::{
2525
self, exe, get_clang_cl_resource_dir, libdir, t, unhashed_basename, up_to_date,
2626
};
27-
use crate::{CLang, GitRepo, Kind, exit, trace};
27+
use crate::{CLang, FileType, GitRepo, Kind, exit, trace};
2828

2929
#[derive(Clone)]
3030
pub struct LlvmResult {
@@ -305,7 +305,10 @@ impl Step for Llvm {
305305
LlvmBuildStatus::ShouldBuild(m) => m,
306306
};
307307

308-
if builder.llvm_link_shared() && target.is_windows() && !target.is_windows_gnullvm() {
308+
if builder.llvm_link_shared()
309+
&& target.is_windows()
310+
&& !(target.is_windows_gnullvm() || target.is_msvc())
311+
{
309312
panic!("shared linking to LLVM is not currently supported on {}", target.triple);
310313
}
311314

@@ -406,6 +409,8 @@ impl Step for Llvm {
406409
// for the tools. We don't do this on every platform as it doesn't work
407410
// equally well everywhere.
408411
if builder.llvm_link_shared() {
412+
cfg.define("LLVM_BUILD_LLVM_DYLIB_VIS", "ON");
413+
cfg.define("LLVM_BUILD_LLVM_DYLIB", "ON");
409414
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
410415
}
411416

@@ -554,12 +559,13 @@ impl Step for Llvm {
554559

555560
cfg.build();
556561

557-
// Helper to find the name of LLVM's shared library on darwin and linux.
562+
// Helper to find the name of LLVM's shared library.
558563
let find_llvm_lib_name = |extension| {
559564
let major = get_llvm_version_major(builder, &res.host_llvm_config);
565+
let prefix = if target.is_msvc() { "" } else { "lib" };
560566
match &llvm_version_suffix {
561-
Some(version_suffix) => format!("libLLVM-{major}{version_suffix}.{extension}"),
562-
None => format!("libLLVM-{major}.{extension}"),
567+
Some(version_suffix) => format!("{prefix}LLVM-{major}{version_suffix}.{extension}"),
568+
None => format!("{prefix}LLVM-{major}.{extension}"),
563569
}
564570
};
565571

@@ -575,6 +581,17 @@ impl Step for Llvm {
575581
}
576582
}
577583

584+
// Create the .dll.lib import file which llvm-config incorrectly points to
585+
if builder.llvm_link_shared() && target.is_msvc() {
586+
let lib_name = find_llvm_lib_name("");
587+
let lib_path = out_dir.join("lib");
588+
let wanted = lib_path.clone().join(lib_name.clone() + "dll.lib");
589+
let wrong = lib_path.join(lib_name + "lib");
590+
if wrong.exists() && !wanted.exists() {
591+
builder.copy_link(&wrong, &wanted, FileType::Regular);
592+
}
593+
}
594+
578595
// When building LLVM as a shared library on linux, it can contain unexpected debuginfo:
579596
// some can come from the C++ standard library. Unless we're explicitly requesting LLVM to
580597
// be built with debuginfo, strip it away after the fact, to make dist artifacts smaller.

0 commit comments

Comments
 (0)