[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 10:08:55 PST 2023


jhuber6 created this revision.
jhuber6 added reviewers: sivachandra, lntue, michaelrj.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
jhuber6 requested review of this revision.

This patch adjusts the way dependencies are handled in the packaed
version of the GPU libc runtime. Previously the files were not getting
updated properly in the install when they changed.

Depends on D144214 <https://reviews.llvm.org/D144214>


Repository:
  rG LLVM Github Monorepo

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,26 @@
   #       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}
+  )
+  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}"
+    ${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.498434.patch
Type: text/x-patch
Size: 2613 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230217/bc6e0619/attachment.bin>


More information about the libc-commits mailing list