@@ -2021,18 +2021,39 @@ fn add_env(builder: &Builder<'_>, cmd: &mut Command, target: TargetSelection) {
20212021 }
20222022}
20232023
2024- fn install_llvm_file ( builder : & Builder < ' _ > , source : & Path , destination : & Path ) {
2024+ fn install_llvm_file (
2025+ builder : & Builder < ' _ > ,
2026+ source : & Path ,
2027+ destination : & Path ,
2028+ install_symlink : bool ,
2029+ ) {
20252030 if builder. config . dry_run ( ) {
20262031 return ;
20272032 }
20282033
2029- builder. install ( source, destination, 0o644 ) ;
2034+ if source. is_symlink ( ) {
2035+ // If we have a symlink like libLLVM-18.so -> libLLVM.so.18.1, install the target of the
2036+ // symlink, which is what will actually get loaded at runtime.
2037+ builder. install ( & t ! ( fs:: canonicalize( source) ) , destination, 0o644 ) ;
2038+ if install_symlink {
2039+ // If requested, also install the symlink. This is used by download-ci-llvm.
2040+ let full_dest = destination. join ( source. file_name ( ) . unwrap ( ) ) ;
2041+ builder. copy ( & source, & full_dest) ;
2042+ }
2043+ } else {
2044+ builder. install ( & source, destination, 0o644 ) ;
2045+ }
20302046}
20312047
20322048/// Maybe add LLVM object files to the given destination lib-dir. Allows either static or dynamic linking.
20332049///
20342050/// Returns whether the files were actually copied.
2035- fn maybe_install_llvm ( builder : & Builder < ' _ > , target : TargetSelection , dst_libdir : & Path ) -> bool {
2051+ fn maybe_install_llvm (
2052+ builder : & Builder < ' _ > ,
2053+ target : TargetSelection ,
2054+ dst_libdir : & Path ,
2055+ install_symlink : bool ,
2056+ ) -> bool {
20362057 // If the LLVM was externally provided, then we don't currently copy
20372058 // artifacts into the sysroot. This is not necessarily the right
20382059 // choice (in particular, it will require the LLVM dylib to be in
@@ -2081,7 +2102,7 @@ fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir
20812102 } else {
20822103 PathBuf :: from ( file)
20832104 } ;
2084- install_llvm_file ( builder, & file, dst_libdir) ;
2105+ install_llvm_file ( builder, & file, dst_libdir, install_symlink ) ;
20852106 }
20862107 !builder. config . dry_run ( )
20872108 } else {
@@ -2096,7 +2117,7 @@ pub fn maybe_install_llvm_target(builder: &Builder<'_>, target: TargetSelection,
20962117 // dynamically linked; it is already included into librustc_llvm
20972118 // statically.
20982119 if builder. llvm_link_shared ( ) {
2099- maybe_install_llvm ( builder, target, & dst_libdir) ;
2120+ maybe_install_llvm ( builder, target, & dst_libdir, false ) ;
21002121 }
21012122}
21022123
@@ -2108,7 +2129,7 @@ pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection
21082129 // dynamically linked; it is already included into librustc_llvm
21092130 // statically.
21102131 if builder. llvm_link_shared ( ) {
2111- maybe_install_llvm ( builder, target, & dst_libdir) ;
2132+ maybe_install_llvm ( builder, target, & dst_libdir, false ) ;
21122133 }
21132134}
21142135
@@ -2203,6 +2224,8 @@ impl Step for RustDev {
22032224
22042225 let mut tarball = Tarball :: new ( builder, "rust-dev" , & target. triple ) ;
22052226 tarball. set_overlay ( OverlayKind :: LLVM ) ;
2227+ // LLVM requires a shared object symlink to exist on some platforms.
2228+ tarball. permit_symlinks ( true ) ;
22062229
22072230 builder. ensure ( crate :: core:: build_steps:: llvm:: Llvm { target } ) ;
22082231
@@ -2243,7 +2266,7 @@ impl Step for RustDev {
22432266 // of `rustc-dev` to support the inherited `-lLLVM` when using the
22442267 // compiler libraries.
22452268 let dst_libdir = tarball. image_dir ( ) . join ( "lib" ) ;
2246- maybe_install_llvm ( builder, target, & dst_libdir) ;
2269+ maybe_install_llvm ( builder, target, & dst_libdir, true ) ;
22472270 let link_type = if builder. llvm_link_shared ( ) { "dynamic" } else { "static" } ;
22482271 t ! ( std:: fs:: write( tarball. image_dir( ) . join( "link-type.txt" ) , link_type) , dst_libdir) ;
22492272
0 commit comments