diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt --- a/libc/CMakeLists.txt +++ b/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) diff --git a/libc/cmake/modules/LLVMLibCHeaderRules.cmake b/libc/cmake/modules/LLVMLibCHeaderRules.cmake --- a/libc/cmake/modules/LLVMLibCHeaderRules.cmake +++ b/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) diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt --- a/libc/test/src/CMakeLists.txt +++ b/libc/test/src/CMakeLists.txt @@ -59,6 +59,15 @@ 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 different 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 "")