[libc-commits] [PATCH] D144280: [libc] Fix dependencies for generating the GPU binary file

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Fri Feb 17 12:06:37 PST 2023


jhuber6 updated this revision to Diff 498475.
jhuber6 added a comment.

Fix deps on the stub making command. Works reliably now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144280/new/

https://reviews.llvm.org/D144280

Files:
  libc/cmake/modules/LLVMLibCObjectRules.cmake


Index: libc/cmake/modules/LLVMLibCObjectRules.cmake
===================================================================
--- libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -132,9 +132,9 @@
   add_custom_command(OUTPUT ${packaged_output_name}
                      COMMAND ${LIBC_CLANG_OFFLOAD_PACKAGER}
                              ${packager_images} -o ${packaged_output_name}
-                     DEPENDS ${gpu_target_names}
+                     DEPENDS ${gpu_target_names} ${ADD_GPU_OBJ_SRCS} ${ADD_GPU_OBJ_HDRS}
                      COMMENT "Packaging LLVM offloading binary")
-  add_custom_target(${packaged_target_name} DEPENDS ${packaged_output_name})
+  add_custom_target(${packaged_target_name} DEPENDS ${packaged_output_name} ${gpu_target_name})
 
   # We create an empty 'stub' file for the host to contain the embedded device
   # code. This will be packaged into 'libcgpu.a'.
@@ -142,20 +142,28 @@
   #       into a single bitcode file and use that. For now we simply build for
   #       every single one and let the offloading linker handle it.
   get_filename_component(stub_filename ${ADD_GPU_OBJ_SRCS} NAME)
-  file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/stubs)
-  file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/stubs/${stub_filename} "// Empty file.\n")
+  add_custom_command(
+    OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/stubs/${stub_filename}"
+    COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/stubs/
+    COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/stubs/${stub_filename}
+    DEPENDS ${gpu_target_names} ${ADD_GPU_OBJ_SRCS} ${ADD_GPU_OBJ_HDRS}
+  )
+  set(stub_target_name ${fq_target_name}.__stub__)
+  add_custom_target(${stub_target_name} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/stubs/${stub_filename})
+
   add_library(
     ${fq_target_name}
     # We want an object library as the objects will eventually get packaged into
     # an archive (like libcgpu.a).
     EXCLUDE_FROM_ALL
     OBJECT
-    "${CMAKE_CURRENT_BINARY_DIR}/stubs/${stub_filename}"
+    ${CMAKE_CURRENT_BINARY_DIR}/stubs/${stub_filename}
   )
   target_compile_options(${fq_target_name} BEFORE PRIVATE ${common_compile_options}
                          -nostdlib -Xclang -fembed-offload-object=${packaged_output_name})
   target_include_directories(${fq_target_name} PRIVATE ${include_dirs})
-  add_dependencies(${fq_target_name} ${full_deps_list} ${packaged_target_name})
+  add_dependencies(${fq_target_name} 
+                   ${full_deps_list} ${packaged_target_name} ${stub_target_name})
 
   # We only build the internal target for a single supported architecture.
   set(include_dirs ${LIBC_BUILD_DIR}/include ${LIBC_SOURCE_DIR} ${LIBC_BUILD_DIR})


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144280.498475.patch
Type: text/x-patch
Size: 2741 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230217/7441156c/attachment.bin>


More information about the libc-commits mailing list