Skip to content

Commit b86d023

Browse files
authored
[libc] Redo the install targets (#78795)
Prior to this change, we wouldn't build headers that aren't referenced by other parts of the libc which would result in a build error during installation. To address this, we make the header target a dependency of the libc archive. Additionally, we also redo the install targets, moving the install targets closer to build targets and simplifying the hierarchy and generally matching what we do for other runtimes.
1 parent b7360fb commit b86d023

File tree

4 files changed

+41
-35
lines changed

4 files changed

+41
-35
lines changed

libc/CMakeLists.txt

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -348,19 +348,6 @@ foreach(entrypoint IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS)
348348
list(APPEND TARGET_ENTRYPOINT_NAME_LIST ${entrypoint_name})
349349
endforeach()
350350

351-
set(LIBC_INSTALL_DEPENDS)
352-
if(LLVM_LIBC_FULL_BUILD)
353-
set(LIBC_INSTALL_DEPENDS "install-libc-static-archives;install-libc-headers")
354-
if(NOT LIBC_TARGET_OS_IS_BAREMETAL)
355-
# For now we will disable libc-startup installation for baremetal. The
356-
# correct way to do it would be to make a hookable startup for baremetal
357-
# and install it as part of the libc installation.
358-
list(APPEND LIBC_INSTALL_DEPENDS "libc-startup")
359-
endif()
360-
else()
361-
set(LIBC_INSTALL_DEPENDS install-libc-static-archives)
362-
endif()
363-
364351
add_subdirectory(include)
365352
add_subdirectory(config)
366353
add_subdirectory(src)
@@ -388,18 +375,3 @@ endif()
388375
if (LIBC_INCLUDE_DOCS)
389376
add_subdirectory(docs)
390377
endif()
391-
392-
393-
if(LLVM_LIBC_FULL_BUILD)
394-
add_llvm_install_targets(
395-
install-libc-headers
396-
DEPENDS libc-headers
397-
COMPONENT libc-headers
398-
)
399-
endif()
400-
401-
add_llvm_install_targets(
402-
install-libc
403-
DEPENDS ${LIBC_INSTALL_DEPENDS}
404-
COMPONENT libc
405-
)

libc/include/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,3 +606,13 @@ foreach(target IN LISTS all_install_header_targets)
606606
COMPONENT libc-headers)
607607
endif()
608608
endforeach()
609+
610+
if(LLVM_LIBC_FULL_BUILD)
611+
add_custom_target(install-libc-headers
612+
DEPENDS libc-headers
613+
COMMAND "${CMAKE_COMMAND}"
614+
-DCMAKE_INSTALL_COMPONENT=libc-headers
615+
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
616+
# Stripping is a no-op for headers
617+
add_custom_target(install-libc-headers-stripped DEPENDS install-libc-headers)
618+
endif()

libc/lib/CMakeLists.txt

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ foreach(archive IN ZIP_LISTS
3333
PROPERTIES
3434
ARCHIVE_OUTPUT_NAME ${archive_0}
3535
)
36+
if(LLVM_LIBC_FULL_BUILD)
37+
target_link_libraries(${archive_1} PUBLIC libc-headers)
38+
endif()
3639
list(APPEND added_archive_targets ${archive_1})
3740
endforeach()
3841

@@ -48,11 +51,32 @@ endif()
4851
install(
4952
TARGETS ${added_archive_targets}
5053
ARCHIVE DESTINATION ${LIBC_INSTALL_LIBRARY_DIR}
51-
COMPONENT libc-static-archives
54+
COMPONENT libc
5255
)
5356

54-
add_llvm_install_targets(
55-
install-libc-static-archives
56-
DEPENDS ${added_archive_targets}
57-
COMPONENT libc-static-archives
58-
)
57+
if(NOT LIBC_TARGET_OS_IS_BAREMETAL)
58+
# For now we will disable libc-startup installation for baremetal. The
59+
# correct way to do it would be to make a hookable startup for baremetal
60+
# and install it as part of the libc installation.
61+
set(startup_target "libc-startup")
62+
endif()
63+
64+
if(LLVM_LIBC_FULL_BUILD)
65+
set(header_install_target install-libc-headers)
66+
endif()
67+
68+
add_custom_target(install-libc
69+
DEPENDS ${added_archive_targets}
70+
${startup_target}
71+
${header_install_target}
72+
COMMAND "${CMAKE_COMMAND}"
73+
-DCMAKE_INSTALL_COMPONENT=libc
74+
-P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
75+
add_custom_target(install-libc-stripped
76+
DEPENDS ${added_archive_targets}
77+
${startup_target}
78+
${header_install_target}
79+
COMMAND "${CMAKE_COMMAND}"
80+
-DCMAKE_INSTALL_COMPONENT=libc
81+
-DCMAKE_INSTALL_DO_STRIP=1
82+
-P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")

libc/utils/gpu/server/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ target_compile_definitions(llvmlibc_rpc_server PUBLIC
1414
# Install the server and associated header.
1515
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/rpc_server.h
1616
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gpu-none-llvm/
17-
COMPONENT libc)
17+
COMPONENT libc-headers)
1818
install(TARGETS llvmlibc_rpc_server
1919
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
2020
COMPONENT libc)

0 commit comments

Comments
 (0)