Skip to content

Commit c4f236e

Browse files
author
Siva Chandra Reddy
committed
[bootstrap build] Add libc-hdrgen as a build dep for libc bootstrap build.
With this change, libc-hdrgen is built like a host build tool like clang and used to build libc for the target. Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D141460
1 parent bb8d719 commit c4f236e

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

llvm/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ foreach(proj IN LISTS LLVM_ENABLE_RUNTIMES)
168168
endif()
169169
endforeach()
170170

171+
if ("libc" IN_LIST LLVM_ENABLE_RUNTIMES)
172+
# To build the libc runtime, we need to be able to build few libc build
173+
# tools from the "libc" project. So, we add it to the list of enabled
174+
# projects.
175+
if (NOT "libc" IN_LIST LLVM_ENABLE_PROJECTS)
176+
message(STATUS "Enabling libc project to build libc build tools")
177+
list(APPEND LLVM_ENABLE_PROJECTS "libc")
178+
endif()
179+
endif()
180+
171181
# LLVM_ENABLE_PROJECTS_USED is `ON` if the user has ever used the
172182
# `LLVM_ENABLE_PROJECTS` CMake cache variable. This exists for
173183
# several reasons:

llvm/runtimes/CMakeLists.txt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ foreach(entry ${runtimes})
193193
endforeach()
194194

195195
function(runtime_default_target)
196-
cmake_parse_arguments(ARG "" "" "DEPENDS;PREFIXES" ${ARGN})
196+
cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;PREFIXES" ${ARGN})
197197

198198
include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
199199
set(SUB_CHECK_TARGETS ${SUB_CHECK_TARGETS} PARENT_SCOPE)
@@ -236,6 +236,7 @@ function(runtime_default_target)
236236
-DCMAKE_ASM_COMPILER_WORKS=ON
237237
${COMMON_CMAKE_ARGS}
238238
${RUNTIMES_CMAKE_ARGS}
239+
${ARG_CMAKE_ARGS}
239240
PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
240241
LLVM_USE_LINKER
241242
${ARG_PREFIXES}
@@ -384,15 +385,31 @@ if(runtimes)
384385
list(APPEND extra_deps llvm-link)
385386
endif()
386387
endif()
388+
if("libc" IN_LIST LLVM_ENABLE_RUNTIMES AND LLVM_LIBC_FULL_BUILD)
389+
if(TARGET libc-hdrgen)
390+
set(libc_tools libc-hdrgen)
391+
set(libc_cmake_args "-DLIBC_HDRGEN_EXE=$<TARGET_FILE:libc-hdrgen>"
392+
"-DLLVM_LIBC_FULL_BUILD=ON")
393+
list(APPEND extra_deps ${libc_tools})
394+
else()
395+
# We want to build the libc build tools before we can build the libc
396+
# itself. So, the libc project should be included in LLVM_ENABLE_PROJECTS.
397+
# This should have been done in llvm/CMakeLists.txt automatically when
398+
# "libc" is detected in LLVM_ENABLE_RUNTIMES.
399+
message(FATAL_ERROR "libc-hdrgen target missing unexpectedly")
400+
endif()
401+
endif()
387402
if(NOT LLVM_RUNTIME_TARGETS)
388403
runtime_default_target(
389404
DEPENDS ${builtins_dep} ${extra_deps}
405+
CMAKE_ARGS ${libc_cmake_args}
390406
PREFIXES ${prefixes})
391407
set(test_targets check-runtimes)
392408
else()
393409
if("default" IN_LIST LLVM_RUNTIME_TARGETS)
394410
runtime_default_target(
395411
DEPENDS ${builtins_dep} ${extra_deps}
412+
CMAKE_ARGS ${libc_cmake_args}
396413
PREFIXES ${prefixes})
397414
list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
398415
else()
@@ -428,7 +445,8 @@ if(runtimes)
428445
endif()
429446
endif()
430447
runtime_register_target(${name} ${name}
431-
DEPENDS ${builtins_dep_name})
448+
DEPENDS ${builtins_dep_name} ${libc_tools}
449+
CMAKE_ARGS ${libc_cmake_args})
432450

433451
add_dependencies(runtimes runtimes-${name})
434452
add_dependencies(runtimes-configure runtimes-${name}-configure)

0 commit comments

Comments
 (0)