Skip to content

Commit 5274a46

Browse files
author
Siva Chandra Reddy
committed
[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
1 parent 3624491 commit 5274a46

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

libc/CMakeLists.txt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,21 @@ set(LIBC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
1414
# The top-level directory in which libc is being built.
1515
set(LIBC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
1616

17-
# For a runtimes build we need to manually include tablgen and LLVM directories.
18-
if ("libc" IN_LIST LLVM_ENABLE_RUNTIMES)
19-
include(TableGen)
20-
set(LLVM_LIBC_INCLUDE_DIRS ${LLVM_MAIN_INCLUDE_DIR} ${LLVM_BINARY_DIR}/include)
17+
if(LLVM_LIBC_FULL_BUILD)
18+
if(NOT LIBC_HDRGEN_EXE)
19+
# We need to set up hdrgen first since other targets depend on it.
20+
add_subdirectory(utils/LibcTableGenUtil)
21+
add_subdirectory(utils/HdrGen)
22+
else()
23+
message(STATUS "Will use ${LIBC_HDRGEN_EXE} for libc header generation.")
24+
endif()
25+
endif()
26+
27+
if(LLVM_ENABLE_RUNTIMES AND NOT LLVM_RUNTIMES_BUILD)
28+
# When libc is build as part of the runtimes/bootstrap build's CMake run, we
29+
# only need to build the host tools to build the libc. So, we just do enough
30+
# to build libc-hdrgen and return.
31+
return()
2132
endif()
2233

2334
# Path libc/scripts directory.
@@ -150,12 +161,6 @@ foreach(entrypoint IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS)
150161
list(APPEND TARGET_ENTRYPOINT_NAME_LIST ${entrypoint_name})
151162
endforeach()
152163

153-
if(LLVM_LIBC_FULL_BUILD)
154-
# We need to set up hdrgen first since other targets depend on it.
155-
add_subdirectory(utils/LibcTableGenUtil)
156-
add_subdirectory(utils/HdrGen)
157-
endif()
158-
159164
set(LIBC_TARGET)
160165
set(LIBC_COMPONENT)
161166
set(LIBC_INSTALL_DEPENDS)

libc/cmake/modules/LLVMLibCHeaderRules.cmake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,23 @@ function(add_gen_header target_name)
108108
set(ENTRYPOINT_NAME_LIST_ARG ${TARGET_ENTRYPOINT_NAME_LIST})
109109
list(TRANSFORM ENTRYPOINT_NAME_LIST_ARG PREPEND "--e=")
110110

111+
if(LIBC_HDRGEN_EXE)
112+
set(hdrgen_exe ${LIBC_HDRGEN_EXE})
113+
else()
114+
set(hdrgen_exe ${LIBC_TABLEGEN_EXE})
115+
set(hdrgen_deps "${LIBC_TABLEGEN_EXE};${LIBC_TABLEGEN_TARGET}")
116+
endif()
111117
add_custom_command(
112118
OUTPUT ${out_file}
113-
COMMAND ${LIBC_TABLEGEN_EXE} -o ${out_file} --header ${ADD_GEN_HDR_GEN_HDR}
119+
COMMAND ${hdrgen_exe} -o ${out_file} --header ${ADD_GEN_HDR_GEN_HDR}
114120
--def ${in_file} ${replacement_params} -I ${LIBC_SOURCE_DIR}
115121
${ENTRYPOINT_NAME_LIST_ARG}
116122
${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
117123

118124
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
119125
DEPENDS ${in_file} ${fq_data_files} ${td_includes}
120126
${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
121-
${LIBC_TABLEGEN_EXE} ${LIBC_TABLEGEN_TARGET}
127+
${hdrgen_deps}
122128
)
123129

124130
if(ADD_GEN_HDR_DEPENDS)

libc/test/src/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ if(${LIBC_TARGET_OS} STREQUAL "linux")
5959
add_subdirectory(pthread)
6060
endif()
6161

62+
if(LLVM_RUNTIMES_BUILD OR LIBC_HDRGEN_EXE)
63+
# The public API test below uses tablegen to generate the test
64+
# source file. Since tablegen is not available during a runtimes
65+
# build, we will skip the test.
66+
# If a different libc-hdrgen binary is being used, then also we
67+
# skip the api-test as we cannot generate the test source file.
68+
return()
69+
endif()
70+
6271
set(public_test ${CMAKE_CURRENT_BINARY_DIR}/public_api_test.cpp)
6372

6473
set(entrypoints_name_list "")

0 commit comments

Comments
 (0)