[libc-commits] [libc] 5274a46 - [libc] Use a prebuilt libc-hdrgen binary if available.
Siva Chandra Reddy via libc-commits
libc-commits at lists.llvm.org
Fri Jan 27 11:53:05 PST 2023
Author: Siva Chandra Reddy
Date: 2023-01-27T19:52:55Z
New Revision: 5274a460dac6ab8620519859a2d59eea37123550
URL: https://github.com/llvm/llvm-project/commit/5274a460dac6ab8620519859a2d59eea37123550
DIFF: https://github.com/llvm/llvm-project/commit/5274a460dac6ab8620519859a2d59eea37123550.diff
LOG: [libc] Use a prebuilt libc-hdrgen binary if available.
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.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D141426
Added:
Modified:
libc/CMakeLists.txt
libc/cmake/modules/LLVMLibCHeaderRules.cmake
libc/test/src/CMakeLists.txt
Removed:
################################################################################
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 7bf1c02e331ff..a293286a4f6d4 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -14,10 +14,21 @@ set(LIBC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
# 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 @@ foreach(entrypoint IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS)
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)
diff --git a/libc/cmake/modules/LLVMLibCHeaderRules.cmake b/libc/cmake/modules/LLVMLibCHeaderRules.cmake
index 729e91481d30e..d41fb0ab78e5f 100644
--- a/libc/cmake/modules/LLVMLibCHeaderRules.cmake
+++ b/libc/cmake/modules/LLVMLibCHeaderRules.cmake
@@ -108,9 +108,15 @@ function(add_gen_header target_name)
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 @@ function(add_gen_header target_name)
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)
diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt
index e47a2452aabe2..1ae18860f396e 100644
--- a/libc/test/src/CMakeLists.txt
+++ b/libc/test/src/CMakeLists.txt
@@ -59,6 +59,15 @@ if(${LIBC_TARGET_OS} STREQUAL "linux")
add_subdirectory(pthread)
endif()
+if(LLVM_RUNTIMES_BUILD OR LIBC_HDRGEN_EXE)
+ # 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.
+ # If a
diff erent libc-hdrgen binary is being used, then also we
+ # skip the api-test as we cannot generate the test source file.
+ return()
+endif()
+
set(public_test ${CMAKE_CURRENT_BINARY_DIR}/public_api_test.cpp)
set(entrypoints_name_list "")
More information about the libc-commits
mailing list