Skip to content

[Offload] Use libc 'hand-in-hand' module to find RPC header #117928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2024

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Nov 27, 2024

Summary:
We should now use the official™ way to include the files from
libc/shared. This required some code to make sure that it's not
included twice if multiple people use it as well as a sanity check on
the directory.

@jhuber6 jhuber6 requested a review from a team as a code owner November 27, 2024 21:25
@llvmbot llvmbot added cmake Build system in general and CMake in particular offload labels Nov 27, 2024
Summary:
We should now use the official™ way to include the files from
`libc/shared`. This required some code to make sure that it's not
included twice if multiple people use it as well as a sanity check on
the directory.
@llvmbot
Copy link
Member

llvmbot commented Nov 27, 2024

@llvm/pr-subscribers-offload

Author: Joseph Huber (jhuber6)

Changes

Summary:
We should now use the official™ way to include the files from
libc/shared. This required some code to make sure that it's not
included twice if multiple people use it as well as a sanity check on
the directory.


Full diff: https://github.com/llvm/llvm-project/pull/117928.diff

3 Files Affected:

  • (modified) offload/CMakeLists.txt (+2)
  • (modified) offload/plugins-nextgen/common/CMakeLists.txt (+3-4)
  • (modified) runtimes/cmake/Modules/FindLibcCommonUtils.cmake (+11-6)
diff --git a/offload/CMakeLists.txt b/offload/CMakeLists.txt
index dfd25bad608436..e24f0faa912117 100644
--- a/offload/CMakeLists.txt
+++ b/offload/CMakeLists.txt
@@ -45,6 +45,8 @@ set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
 list(INSERT CMAKE_MODULE_PATH 0
   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
+  "${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules"
+  "${LLVM_COMMON_CMAKE_UTILS}"
   "${LLVM_COMMON_CMAKE_UTILS}/Modules"
   )
 
diff --git a/offload/plugins-nextgen/common/CMakeLists.txt b/offload/plugins-nextgen/common/CMakeLists.txt
index 93cf42c89f321e..3a861a47eedabc 100644
--- a/offload/plugins-nextgen/common/CMakeLists.txt
+++ b/offload/plugins-nextgen/common/CMakeLists.txt
@@ -22,17 +22,16 @@ if (NOT LLVM_LINK_LLVM_DYLIB)
 endif()
 
 # Include the RPC server from the `libc` project if availible.
+include(FindLibcCommonUtils)
 if(TARGET llvmlibc_rpc_server AND ${LIBOMPTARGET_GPU_LIBC_SUPPORT})
-	target_link_libraries(PluginCommon PRIVATE llvmlibc_rpc_server)
+	target_link_libraries(PluginCommon PRIVATE llvmlibc_rpc_server llvm-libc-common-utilities)
 	target_compile_definitions(PluginCommon PRIVATE LIBOMPTARGET_RPC_SUPPORT)
 elseif(${LIBOMPTARGET_GPU_LIBC_SUPPORT})
   find_library(llvmlibc_rpc_server NAMES llvmlibc_rpc_server
                PATHS ${LIBOMPTARGET_LLVM_LIBRARY_DIR} NO_DEFAULT_PATH)
   if(llvmlibc_rpc_server)
-		target_link_libraries(PluginCommon PRIVATE ${llvmlibc_rpc_server})
+    target_link_libraries(PluginCommon PRIVATE ${llvmlibc_rpc_server} llvm-libc-common-utilities)
 		target_compile_definitions(PluginCommon PRIVATE LIBOMPTARGET_RPC_SUPPORT)
-    # We may need to get the headers directly from the 'libc' source directory.
-    target_include_directories(PluginCommon PRIVATE ${CMAKE_SOURCE_DIR}/../libc/)
   endif()
 endif()
 
diff --git a/runtimes/cmake/Modules/FindLibcCommonUtils.cmake b/runtimes/cmake/Modules/FindLibcCommonUtils.cmake
index 763dc81d8bd733..0e65fdff7c34b9 100644
--- a/runtimes/cmake/Modules/FindLibcCommonUtils.cmake
+++ b/runtimes/cmake/Modules/FindLibcCommonUtils.cmake
@@ -6,9 +6,14 @@
 #
 #===--------------------------------------------------------------------===//
 
-add_library(llvm-libc-common-utilities INTERFACE)
-# TODO: Reorganize the libc shared section so that it can be included without
-# adding the root "libc" directory to the include path.
-target_include_directories(llvm-libc-common-utilities INTERFACE ${CMAKE_CURRENT_LIST_DIR}/../../../libc)
-target_compile_definitions(llvm-libc-common-utilities INTERFACE LIBC_NAMESPACE=__llvm_libc_common_utils)
-target_compile_features(llvm-libc-common-utilities INTERFACE cxx_std_17)
+if(NOT TARGET llvm-libc-common-utilities)
+  set(libc_path ${CMAKE_CURRENT_LIST_DIR}/../../../libc)
+  if (EXISTS ${libc_path} AND IS_DIRECTORY ${libc_path})
+    add_library(llvm-libc-common-utilities INTERFACE)
+    # TODO: Reorganize the libc shared section so that it can be included without
+    # adding the root "libc" directory to the include path.
+    target_include_directories(llvm-libc-common-utilities INTERFACE ${libc_path})
+    target_compile_definitions(llvm-libc-common-utilities INTERFACE LIBC_NAMESPACE=__llvm_libc_common_utils)
+    target_compile_features(llvm-libc-common-utilities INTERFACE cxx_std_17)
+  endif()
+endif()

Copy link
Contributor

@SchrodingerZhu SchrodingerZhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach looks good to me

@jhuber6 jhuber6 merged commit a24aa7d into llvm:main Nov 28, 2024
60 checks passed
Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the cleanup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular offload
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants