[libc-commits] [PATCH] D141426: [libc] Use a prebuilt libc-hdrgen binary if available.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Jan 10 13:20:54 PST 2023


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

This feature will primarily by used by the runtimes build. In the
runtimes build, we build libc-hdrgen once for the host and use it
to build the libc for other targets. So, the host libc-hdrgen is
like a prebuilt passed to the target builds.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141426

Files:
  libc/CMakeLists.txt
  libc/cmake/modules/LLVMLibCHeaderRules.cmake
  libc/test/src/CMakeLists.txt


Index: libc/test/src/CMakeLists.txt
===================================================================
--- libc/test/src/CMakeLists.txt
+++ libc/test/src/CMakeLists.txt
@@ -59,6 +59,13 @@
   add_subdirectory(pthread)
 endif()
 
+if(LLVM_RUNTIMES_BUILD)
+  # The public API test below uses tablegen to generate the test
+  # source file. Since tablegen is not available during a runtimes
+  # build, we will skip the test.
+  return()
+endif()
+
 set(public_test ${CMAKE_CURRENT_BINARY_DIR}/public_api_test.cpp)
 
 set(entrypoints_name_list "")
Index: libc/cmake/modules/LLVMLibCHeaderRules.cmake
===================================================================
--- libc/cmake/modules/LLVMLibCHeaderRules.cmake
+++ libc/cmake/modules/LLVMLibCHeaderRules.cmake
@@ -108,9 +108,15 @@
   set(ENTRYPOINT_NAME_LIST_ARG ${TARGET_ENTRYPOINT_NAME_LIST})
   list(TRANSFORM ENTRYPOINT_NAME_LIST_ARG PREPEND "--e=")
 
+  if(LIBC_HDRGEN_EXE)
+    set(hdrgen_exe ${LIBC_HDRGEN_EXE})
+  else()
+    set(hdrgen_exe ${LIBC_TABLEGEN_EXE})
+    set(hdrgen_deps "${LIBC_TABLEGEN_EXE};${LIBC_TABLEGEN_TARGET}")
+  endif()
   add_custom_command(
     OUTPUT ${out_file}
-    COMMAND ${LIBC_TABLEGEN_EXE} -o ${out_file} --header ${ADD_GEN_HDR_GEN_HDR}
+    COMMAND ${hdrgen_exe} -o ${out_file} --header ${ADD_GEN_HDR_GEN_HDR}
             --def ${in_file} ${replacement_params} -I ${LIBC_SOURCE_DIR}
            ${ENTRYPOINT_NAME_LIST_ARG}
            ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
@@ -118,7 +124,7 @@
     WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
     DEPENDS ${in_file} ${fq_data_files} ${td_includes}
             ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
-            ${LIBC_TABLEGEN_EXE} ${LIBC_TABLEGEN_TARGET}
+            ${hdrgen_deps}
   )
 
   if(ADD_GEN_HDR_DEPENDS)
Index: libc/CMakeLists.txt
===================================================================
--- libc/CMakeLists.txt
+++ libc/CMakeLists.txt
@@ -14,10 +14,21 @@
 # The top-level directory in which libc is being built.
 set(LIBC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
 
-# For a runtimes build we need to manually include tablgen and LLVM directories.
-if ("libc" IN_LIST LLVM_ENABLE_RUNTIMES)
-  include(TableGen)
-  set(LLVM_LIBC_INCLUDE_DIRS ${LLVM_MAIN_INCLUDE_DIR} ${LLVM_BINARY_DIR}/include)
+if(LLVM_LIBC_FULL_BUILD)
+  if(NOT LIBC_HDRGEN_EXE)
+    # We need to set up hdrgen first since other targets depend on it.
+    add_subdirectory(utils/LibcTableGenUtil)
+    add_subdirectory(utils/HdrGen)
+  else()
+    message(STATUS "Will use ${LIBC_HDRGEN_EXE} for libc header generation.")
+  endif()
+endif()
+
+if(LLVM_ENABLE_RUNTIMES AND NOT LLVM_RUNTIMES_BUILD)
+  # When libc is build as part of the runtimes/bootstrap build's CMake run, we
+  # only need to build the host tools to build the libc. So, we just do enough
+  # to build libc-hdrgen and return.
+  return()
 endif()
 
 # Path libc/scripts directory.
@@ -150,12 +161,6 @@
   list(APPEND TARGET_ENTRYPOINT_NAME_LIST ${entrypoint_name})
 endforeach()
 
-if(LLVM_LIBC_FULL_BUILD)
-  # We need to set up hdrgen first since other targets depend on it.
-  add_subdirectory(utils/LibcTableGenUtil)
-  add_subdirectory(utils/HdrGen)
-endif()
-
 set(LIBC_TARGET)
 set(LIBC_COMPONENT)
 set(LIBC_INSTALL_DEPENDS)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141426.487965.patch
Type: text/x-patch
Size: 3269 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230110/3a47cc95/attachment.bin>


More information about the libc-commits mailing list