@@ -1885,6 +1885,34 @@ impl Step for HashSign {
18851885 }
18861886}
18871887
1888+ // Maybe add libLLVM.so to the lib-dir. It will only have been built if
1889+ // LLVM tools are linked dynamically.
1890+ // Note: This function does no yet support Windows but we also don't support
1891+ // linking LLVM tools dynamically on Windows yet.
1892+ fn maybe_install_llvm_dylib ( builder : & Builder ,
1893+ target : Interned < String > ,
1894+ image : & Path ) {
1895+ let src_libdir = builder
1896+ . llvm_out ( target)
1897+ . join ( "lib" ) ;
1898+
1899+ // Usually libLLVM.so is a symlink to something like libLLVM-6.0.so.
1900+ // Since tools link to the latter rather than the former, we have to
1901+ // follow the symlink to find out what to distribute.
1902+ let llvm_dylib_path = src_libdir. join ( "libLLVM.so" ) ;
1903+ if llvm_dylib_path. exists ( ) {
1904+ let llvm_dylib_path = llvm_dylib_path. canonicalize ( ) . unwrap_or_else ( |e| {
1905+ panic ! ( "dist: Error calling canonicalize path `{}`: {}" ,
1906+ llvm_dylib_path. display( ) , e) ;
1907+ } ) ;
1908+
1909+ let dst_libdir = image. join ( "lib" ) ;
1910+ t ! ( fs:: create_dir_all( & dst_libdir) ) ;
1911+
1912+ builder. install ( & llvm_dylib_path, & dst_libdir, 0o644 ) ;
1913+ }
1914+ }
1915+
18881916#[ derive( Clone , Debug , Eq , Hash , PartialEq ) ]
18891917pub struct LlvmTools {
18901918 pub stage : u32 ,
@@ -1929,18 +1957,18 @@ impl Step for LlvmTools {
19291957 drop ( fs:: remove_dir_all ( & image) ) ;
19301958
19311959 // Prepare the image directory
1932- let bindir = builder
1960+ let src_bindir = builder
19331961 . llvm_out ( target)
19341962 . join ( "bin" ) ;
1935- let dst = image. join ( "lib/rustlib" )
1936- . join ( target)
1937- . join ( "bin" ) ;
1938- t ! ( fs:: create_dir_all( & dst) ) ;
1963+ let dst_bindir = image. join ( "bin" ) ;
1964+ t ! ( fs:: create_dir_all( & dst_bindir) ) ;
19391965 for tool in LLVM_TOOLS {
1940- let exe = bindir . join ( exe ( tool, & target) ) ;
1941- builder. install ( & exe, & dst , 0o755 ) ;
1966+ let exe = src_bindir . join ( exe ( tool, & target) ) ;
1967+ builder. install ( & exe, & dst_bindir , 0o755 ) ;
19421968 }
19431969
1970+ maybe_install_llvm_dylib ( builder, target, & image) ;
1971+
19441972 // Prepare the overlay
19451973 let overlay = tmp. join ( "llvm-tools-overlay" ) ;
19461974 drop ( fs:: remove_dir_all ( & overlay) ) ;
@@ -2025,7 +2053,6 @@ impl Step for Lldb {
20252053 let dst = image. join ( "lib" ) ;
20262054 t ! ( fs:: create_dir_all( & dst) ) ;
20272055 for entry in t ! ( fs:: read_dir( & libdir) ) {
2028- // let entry = t!(entry);
20292056 let entry = entry. unwrap ( ) ;
20302057 if let Ok ( name) = entry. file_name ( ) . into_string ( ) {
20312058 if name. starts_with ( "liblldb." ) && !name. ends_with ( ".a" ) {
@@ -2060,6 +2087,9 @@ impl Step for Lldb {
20602087 }
20612088 }
20622089
2090+ // Copy libLLVM.so to the lib dir as well, if needed.
2091+ maybe_install_llvm_dylib ( builder, target, & image) ;
2092+
20632093 // Prepare the overlay
20642094 let overlay = tmp. join ( "lldb-overlay" ) ;
20652095 drop ( fs:: remove_dir_all ( & overlay) ) ;
0 commit comments