@@ -238,9 +238,7 @@ impl Step for Llvm {
238
238
} ;
239
239
240
240
builder. update_submodule ( & Path :: new ( "src" ) . join ( "llvm-project" ) ) ;
241
- if builder. llvm_link_shared ( )
242
- && ( target. contains ( "windows" ) || target. contains ( "apple-darwin" ) )
243
- {
241
+ if builder. llvm_link_shared ( ) && target. contains ( "windows" ) {
244
242
panic ! ( "shared linking to LLVM is not currently supported on {}" , target. triple) ;
245
243
}
246
244
@@ -346,7 +344,9 @@ impl Step for Llvm {
346
344
//
347
345
// If we're not linking rustc to a dynamic LLVM, though, then don't link
348
346
// tools to it.
349
- if builder. llvm_link_tools_dynamically ( target) && builder. llvm_link_shared ( ) {
347
+ let llvm_link_shared =
348
+ builder. llvm_link_tools_dynamically ( target) && builder. llvm_link_shared ( ) ;
349
+ if llvm_link_shared {
350
350
cfg. define ( "LLVM_LINK_LLVM_DYLIB" , "ON" ) ;
351
351
}
352
352
@@ -425,18 +425,18 @@ impl Step for Llvm {
425
425
) ;
426
426
}
427
427
428
- if let Some ( ref suffix) = builder. config . llvm_version_suffix {
428
+ let llvm_version_suffix = if let Some ( ref suffix) = builder. config . llvm_version_suffix {
429
429
// Allow version-suffix="" to not define a version suffix at all.
430
- if !suffix. is_empty ( ) {
431
- cfg. define ( "LLVM_VERSION_SUFFIX" , suffix) ;
432
- }
430
+ if !suffix. is_empty ( ) { Some ( suffix. to_string ( ) ) } else { None }
433
431
} else if builder. config . channel == "dev" {
434
432
// Changes to a version suffix require a complete rebuild of the LLVM.
435
433
// To avoid rebuilds during a time of version bump, don't include rustc
436
434
// release number on the dev channel.
437
- cfg . define ( "LLVM_VERSION_SUFFIX" , " -rust-dev") ;
435
+ Some ( " -rust-dev". to_string ( ) )
438
436
} else {
439
- let suffix = format ! ( "-rust-{}-{}" , builder. version, builder. config. channel) ;
437
+ Some ( format ! ( "-rust-{}-{}" , builder. version, builder. config. channel) )
438
+ } ;
439
+ if let Some ( ref suffix) = llvm_version_suffix {
440
440
cfg. define ( "LLVM_VERSION_SUFFIX" , suffix) ;
441
441
}
442
442
@@ -465,6 +465,27 @@ impl Step for Llvm {
465
465
466
466
cfg. build ( ) ;
467
467
468
+ // When building LLVM with LLVM_LINK_LLVM_DYLIB for macOS, an unversioned
469
+ // libLLVM.dylib will be built. However, llvm-config will still look
470
+ // for a versioned path like libLLVM-14.dylib. Manually create a symbolic
471
+ // link to make llvm-config happy.
472
+ if llvm_link_shared && target. contains ( "apple-darwin" ) {
473
+ let mut cmd = Command :: new ( & build_llvm_config) ;
474
+ let version = output ( cmd. arg ( "--version" ) ) ;
475
+ let major = version. split ( '.' ) . next ( ) . unwrap ( ) ;
476
+ let lib_name = match llvm_version_suffix {
477
+ Some ( s) => format ! ( "lib/libLLVM-{}{}.dylib" , major, s) ,
478
+ None => format ! ( "lib/libLLVM-{}.dylib" , major) ,
479
+ } ;
480
+
481
+ // The reason why we build the library path from llvm-config is because
482
+ // the output of llvm-config depends on its location in the file system.
483
+ // Make sure we create the symlink exactly where it's needed.
484
+ let llvm_base = build_llvm_config. parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) ;
485
+ let lib_llvm = llvm_base. join ( lib_name) ;
486
+ t ! ( builder. symlink_file( "libLLVM.dylib" , & lib_llvm) ) ;
487
+ }
488
+
468
489
t ! ( stamp. write( ) ) ;
469
490
470
491
build_llvm_config
0 commit comments