@@ -1046,8 +1046,25 @@ pub struct BuiltOmpOffload {
10461046}
10471047
10481048impl BuiltOmpOffload {
1049- pub fn offload_paths ( & self ) -> Vec < PathBuf > {
1050- self . offload . clone ( )
1049+ pub fn artifact_paths_with_symlink_targets ( & self ) -> Vec < PathBuf > {
1050+ let mut paths = self . offload . clone ( ) ;
1051+
1052+ for path in & self . offload {
1053+ let mut current = path. clone ( ) ;
1054+
1055+ while t ! ( fs:: symlink_metadata( & current) ) . file_type ( ) . is_symlink ( ) {
1056+ let target = t ! ( fs:: read_link( & current) ) ;
1057+ current = current. parent ( ) . unwrap ( ) . join ( target) ;
1058+
1059+ if paths. contains ( & current) {
1060+ break ;
1061+ }
1062+
1063+ paths. push ( current. clone ( ) ) ;
1064+ }
1065+ }
1066+
1067+ paths
10511068 }
10521069}
10531070
@@ -1101,6 +1118,30 @@ impl CommandLineStep for OmpOffload {
11011118 files. push ( out_dir. join ( "lib" ) . join ( "libLLVMOffload" ) . with_extension ( lib_ext) ) ;
11021119 files. push ( out_dir. join ( "lib" ) . join ( "libomp" ) . with_extension ( lib_ext) ) ;
11031120 files. push ( out_dir. join ( "lib" ) . join ( "libomptarget" ) . with_extension ( lib_ext) ) ;
1121+ files. push (
1122+ out_dir. join ( "lib" ) . join ( "amdgcn-amd-amdhsa" ) . join ( "libompdevice" ) . with_extension ( "a" ) ,
1123+ ) ;
1124+ files. push (
1125+ out_dir
1126+ . join ( "lib" )
1127+ . join ( "amdgcn-amd-amdhsa" )
1128+ . join ( "libomptarget-amdgpu" )
1129+ . with_extension ( "bc" ) ,
1130+ ) ;
1131+ files. push (
1132+ out_dir
1133+ . join ( "lib" )
1134+ . join ( "nvptx64-nvidia-cuda" )
1135+ . join ( "libompdevice" )
1136+ . with_extension ( "a" ) ,
1137+ ) ;
1138+ files. push (
1139+ out_dir
1140+ . join ( "lib" )
1141+ . join ( "nvptx64-nvidia-cuda" )
1142+ . join ( "libomptarget-nvptx" )
1143+ . with_extension ( "bc" ) ,
1144+ ) ;
11041145
11051146 // Offload/OpenMP are just subfolders of LLVM, so we can use the LLVM sha.
11061147 static STAMP_HASH_MEMO : OnceLock < String > = OnceLock :: new ( ) ;
@@ -1167,7 +1208,15 @@ impl CommandLineStep for OmpOffload {
11671208 cflags. push_all ( format ! ( " -I {inc_dir}" ) ) ;
11681209 }
11691210
1170- configure_cmake ( builder, target, & mut cfg, true , LdFlags :: default ( ) , cflags, & [ ] ) ;
1211+ // Logic copied from `configure_llvm`
1212+ // ThinLTO is only available when building with LLVM, enabling LLD is required.
1213+ // Apple's linker ld64 supports ThinLTO out of the box though, so don't use LLD on Darwin.
1214+ let mut ldflags = LdFlags :: default ( ) ;
1215+ if builder. config . llvm_thin_lto && !target. contains ( "apple" ) {
1216+ ldflags. push_all ( "-fuse-ld=lld" ) ;
1217+ }
1218+
1219+ configure_cmake ( builder, target, & mut cfg, true , ldflags, cflags, & [ ] ) ;
11711220
11721221 // Re-use the same flags as llvm to control the level of debug information
11731222 // generated for offload.
@@ -1196,6 +1245,7 @@ impl CommandLineStep for OmpOffload {
11961245 cfg. define ( "LLVM_ENABLE_RUNTIMES" , "openmp;offload" ) ;
11971246 } else {
11981247 // OpenMP provides some device libraries, so we also compile it for all gpu targets.
1248+ cfg. define ( "OPENMP_INSTALL_LIBDIR" , Path :: new ( "lib" ) . join ( omp_target) ) ;
11991249 cfg. define ( "LLVM_USE_LINKER" , "lld" ) ;
12001250 cfg. define ( "LLVM_ENABLE_RUNTIMES" , "openmp" ) ;
12011251 cfg. define ( "CMAKE_C_COMPILER_TARGET" , omp_target) ;
0 commit comments