@@ -941,8 +941,25 @@ pub struct BuiltOmpOffload {
941941}
942942
943943impl BuiltOmpOffload {
944- pub fn offload_paths ( & self ) -> Vec < PathBuf > {
945- self . offload . clone ( )
944+ pub fn artifact_paths_with_symlink_targets ( & self ) -> Vec < PathBuf > {
945+ let mut paths = self . offload . clone ( ) ;
946+
947+ for path in & self . offload {
948+ let mut current = path. clone ( ) ;
949+
950+ while t ! ( fs:: symlink_metadata( & current) ) . file_type ( ) . is_symlink ( ) {
951+ let target = t ! ( fs:: read_link( & current) ) ;
952+ current = current. parent ( ) . unwrap ( ) . join ( target) ;
953+
954+ if paths. contains ( & current) {
955+ break ;
956+ }
957+
958+ paths. push ( current. clone ( ) ) ;
959+ }
960+ }
961+
962+ paths
946963 }
947964}
948965
@@ -997,6 +1014,30 @@ impl Step for OmpOffload {
9971014 files. push ( out_dir. join ( "lib" ) . join ( "libLLVMOffload" ) . with_extension ( lib_ext) ) ;
9981015 files. push ( out_dir. join ( "lib" ) . join ( "libomp" ) . with_extension ( lib_ext) ) ;
9991016 files. push ( out_dir. join ( "lib" ) . join ( "libomptarget" ) . with_extension ( lib_ext) ) ;
1017+ files. push (
1018+ out_dir. join ( "lib" ) . join ( "amdgcn-amd-amdhsa" ) . join ( "libompdevice" ) . with_extension ( "a" ) ,
1019+ ) ;
1020+ files. push (
1021+ out_dir
1022+ . join ( "lib" )
1023+ . join ( "amdgcn-amd-amdhsa" )
1024+ . join ( "libomptarget-amdgpu" )
1025+ . with_extension ( "bc" ) ,
1026+ ) ;
1027+ files. push (
1028+ out_dir
1029+ . join ( "lib" )
1030+ . join ( "nvptx64-nvidia-cuda" )
1031+ . join ( "libompdevice" )
1032+ . with_extension ( "a" ) ,
1033+ ) ;
1034+ files. push (
1035+ out_dir
1036+ . join ( "lib" )
1037+ . join ( "nvptx64-nvidia-cuda" )
1038+ . join ( "libomptarget-nvptx" )
1039+ . with_extension ( "bc" ) ,
1040+ ) ;
10001041
10011042 // Offload/OpenMP are just subfolders of LLVM, so we can use the LLVM sha.
10021043 static STAMP_HASH_MEMO : OnceLock < String > = OnceLock :: new ( ) ;
@@ -1063,7 +1104,15 @@ impl Step for OmpOffload {
10631104 cflags. push_all ( format ! ( " -I {inc_dir}" ) ) ;
10641105 }
10651106
1066- configure_cmake ( builder, target, & mut cfg, true , LdFlags :: default ( ) , cflags, & [ ] ) ;
1107+ // Logic copied from `configure_llvm`
1108+ // ThinLTO is only available when building with LLVM, enabling LLD is required.
1109+ // Apple's linker ld64 supports ThinLTO out of the box though, so don't use LLD on Darwin.
1110+ let mut ldflags = LdFlags :: default ( ) ;
1111+ if builder. config . llvm_thin_lto && !target. contains ( "apple" ) {
1112+ ldflags. push_all ( "-fuse-ld=lld" ) ;
1113+ }
1114+
1115+ configure_cmake ( builder, target, & mut cfg, true , ldflags, cflags, & [ ] ) ;
10671116
10681117 // Re-use the same flags as llvm to control the level of debug information
10691118 // generated for offload.
@@ -1097,6 +1146,7 @@ impl Step for OmpOffload {
10971146 cfg. define ( "LLVM_ENABLE_RUNTIMES" , "openmp;offload" ) ;
10981147 } else {
10991148 // OpenMP provides some device libraries, so we also compile it for all gpu targets.
1149+ cfg. define ( "OPENMP_INSTALL_LIBDIR" , Path :: new ( "lib" ) . join ( omp_target) ) ;
11001150 cfg. define ( "LLVM_USE_LINKER" , "lld" ) ;
11011151 cfg. define ( "LLVM_ENABLE_RUNTIMES" , "openmp" ) ;
11021152 cfg. define ( "CMAKE_C_COMPILER_TARGET" , omp_target) ;
0 commit comments