@@ -24,7 +24,7 @@ use crate::utils::exec::command;
2424use 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 ) ]
3030pub struct LlvmResult {
@@ -305,7 +305,7 @@ 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 ( ) && target. is_windows ( ) && !( target. is_windows_gnullvm ( ) || target . is_msvc ( ) ) {
309309 panic ! ( "shared linking to LLVM is not currently supported on {}" , target. triple) ;
310310 }
311311
@@ -406,6 +406,8 @@ impl Step for Llvm {
406406 // for the tools. We don't do this on every platform as it doesn't work
407407 // equally well everywhere.
408408 if builder. llvm_link_shared ( ) {
409+ cfg. define ( "LLVM_BUILD_LLVM_DYLIB_VIS" , "ON" ) ;
410+ cfg. define ( "LLVM_BUILD_LLVM_DYLIB" , "ON" ) ;
409411 cfg. define ( "LLVM_LINK_LLVM_DYLIB" , "ON" ) ;
410412 }
411413
@@ -554,12 +556,13 @@ impl Step for Llvm {
554556
555557 cfg. build ( ) ;
556558
557- // Helper to find the name of LLVM's shared library on darwin and linux .
559+ // Helper to find the name of LLVM's shared library.
558560 let find_llvm_lib_name = |extension| {
559561 let major = get_llvm_version_major ( builder, & res. host_llvm_config ) ;
562+ let prefix = if target. is_msvc ( ) { "" } else { "lib" } ;
560563 match & llvm_version_suffix {
561- Some ( version_suffix) => format ! ( "libLLVM -{major}{version_suffix}.{extension}" ) ,
562- None => format ! ( "libLLVM -{major}.{extension}" ) ,
564+ Some ( version_suffix) => format ! ( "{prefix}LLVM -{major}{version_suffix}.{extension}" ) ,
565+ None => format ! ( "{prefix}LLVM -{major}.{extension}" ) ,
563566 }
564567 } ;
565568
@@ -575,6 +578,17 @@ impl Step for Llvm {
575578 }
576579 }
577580
581+ // Create the .dll.lib import file with llvm-config incorrectly points to
582+ if builder. llvm_link_shared ( ) && target. is_msvc ( ) {
583+ let lib_name = find_llvm_lib_name ( "" ) ;
584+ let lib_path = out_dir. join ( "lib" ) ;
585+ let wanted = lib_path. clone ( ) . join ( lib_name. clone ( ) + "dll.lib" ) ;
586+ let wrong = lib_path. join ( lib_name + "lib" ) ;
587+ if wrong. exists ( ) && !wanted. exists ( ) {
588+ builder. copy_link ( & wrong, & wanted, FileType :: Regular ) ;
589+ }
590+ }
591+
578592 // When building LLVM as a shared library on linux, it can contain unexpected debuginfo:
579593 // some can come from the C++ standard library. Unless we're explicitly requesting LLVM to
580594 // be built with debuginfo, strip it away after the fact, to make dist artifacts smaller.
0 commit comments