LibC: Symlink headers into the sysroot at configure-time

This removes the need to have the install_libc_headers target, since
LibC's headers will now get installed before anything gets built. By
extension, this also prevents said target from re-running on every
build.
This commit is contained in:
implicitfield
2024-11-20 15:26:53 +02:00
committed by Nico Weber
parent 72b2e40ce1
commit 175f9dc5c3
9 changed files with 6 additions and 28 deletions

View File

@@ -803,11 +803,10 @@ add_compile_definitions(KERNEL)
add_link_options(LINKER:-z,notext)
add_library(kernel_heap STATIC ${KERNEL_HEAP_SOURCES})
add_dependencies(kernel_heap install_libc_headers)
target_link_libraries(kernel_heap PUBLIC GenericClangPlugin)
add_executable(Kernel ${SOURCES})
add_dependencies(Kernel generate_EscapeSequenceStateMachine.h generate_version_header install_libc_headers)
add_dependencies(Kernel generate_EscapeSequenceStateMachine.h generate_version_header)
target_link_libraries(Kernel PUBLIC GenericClangPlugin)
if("${SERENITY_ARCH}" STREQUAL "aarch64")

View File

@@ -40,7 +40,6 @@ add_compile_definitions(PREKERNEL)
add_executable(${PREKERNEL_TARGET} ${SOURCES} $<TARGET_OBJECTS:KernelObject>)
add_dependencies(${PREKERNEL_TARGET} Kernel)
add_dependencies(${PREKERNEL_TARGET} install_libc_headers)
target_compile_options(${PREKERNEL_TARGET} PRIVATE -no-pie -fno-pic -fno-threadsafe-statics)
target_link_options(${PREKERNEL_TARGET} PRIVATE LINKER:-T ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld -nostdlib LINKER:--no-pie)

View File

@@ -8,7 +8,6 @@ target_compile_definitions(DynamicLoader_CompileOptions INTERFACE NO_TLS _DYNAMI
target_compile_options(DynamicLoader_CompileOptions INTERFACE -fno-rtti -fpie -ffunction-sections -fdata-sections)
target_link_options(DynamicLoader_CompileOptions INTERFACE -nolibc -nostdlib++ -nostartfiles -static-libgcc -fpie -Wl,--gc-sections)
target_link_options(DynamicLoader_CompileOptions INTERFACE -fno-sanitize=undefined) # Sanitizer runtime is linked in manually
add_dependencies(DynamicLoader_CompileOptions install_libc_headers)
add_executable(Loader.so ${SOURCES})

View File

@@ -218,27 +218,20 @@ set(HEADERS
)
# ===== LibC headers =====
add_custom_target(install_libc_headers)
# Copy LibC's headers into the sysroot to satisfy libc++'s include priority requirements.
# NOTE: We have to symlink LibC's headers into the sysroot to satisfy libc++'s include priority
# requirements.
foreach(RELATIVE_HEADER_PATH IN LISTS HEADERS)
get_filename_component(directory ${RELATIVE_HEADER_PATH} DIRECTORY)
get_filename_component(name ${RELATIVE_HEADER_PATH} NAME)
string(REPLACE "../" "" subdirectory "${directory}")
file(MAKE_DIRECTORY "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${subdirectory}")
add_custom_command(
TARGET install_libc_headers
PRE_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${RELATIVE_HEADER_PATH}" "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${subdirectory}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
VERBATIM
)
file(CREATE_LINK "${CMAKE_CURRENT_SOURCE_DIR}/${RELATIVE_HEADER_PATH}" "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${subdirectory}/${name}" SYMBOLIC)
endforeach()
# ===== Start files =====
# NOTE: We link all these against NoCoverage so that we don't break ports by requiring coverage
# symbols in runtime/startup objects.
add_library(crt0 STATIC crt0.cpp)
add_dependencies(crt0 install_libc_headers)
target_link_libraries(crt0 PRIVATE NoCoverage)
add_custom_command(
TARGET crt0
@@ -249,7 +242,6 @@ add_custom_command(
# some convincing that this is the case.
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_library(crt0_shared STATIC crt0_shared.cpp)
add_dependencies(crt0_shared install_libc_headers)
target_link_libraries(crt0_shared PRIVATE NoCoverage)
add_custom_command(
TARGET crt0_shared
@@ -283,7 +275,7 @@ else()
endif()
serenity_libc(LibC c)
add_dependencies(LibC crt0 install_libc_headers)
add_dependencies(LibC crt0)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_dependencies(LibC crti crt0_shared crtn)
endif()

View File

@@ -3,7 +3,6 @@
# To avoid a circular dependency chain with LibCrypt --> LibCrypto --> LibCore --> LibCrypt
# We include the SHA2 implementation from LibCrypto here manually
add_library(LibCryptSHA2 OBJECT ../LibCrypto/Hash/SHA2.cpp)
add_dependencies(LibCryptSHA2 install_libc_headers)
set_target_properties(LibCryptSHA2 PROPERTIES CXX_VISIBILITY_PRESET hidden)
set_target_properties(LibCryptSHA2 PROPERTIES VISIBILITY_INLINES_HIDDEN ON)

View File

@@ -4,7 +4,6 @@ set(SOURCES
)
serenity_libc(LibUBSanitizer ubsan)
add_dependencies(LibUBSanitizer install_libc_headers)
target_link_options(LibUBSanitizer PRIVATE -nostdlib)
add_library(DynamicLoader_LibUBSanitizer STATIC UBSanitizer.cpp)

View File

@@ -3,7 +3,6 @@ set(SOURCES
)
serenity_libc(LibSystem system)
add_dependencies(LibSystem install_libc_headers)
target_link_options(LibSystem PRIVATE -nostdlib)
add_library(DynamicLoader_LibSystem STATIC ${SOURCES})

View File

@@ -11,8 +11,3 @@ target_link_libraries(LibTest PRIVATE LibCore)
add_library(LibTestMain OBJECT TestMain.cpp)
add_library(JavaScriptTestRunnerMain OBJECT JavaScriptTestRunnerMain.cpp)
if (SERENITYOS)
add_dependencies(LibTestMain install_libc_headers)
add_dependencies(JavaScriptTestRunnerMain install_libc_headers)
endif()

View File

@@ -13,6 +13,3 @@ target_compile_definitions(LibTimeZone PRIVATE ENABLE_TIME_ZONE_DATA=$<BOOL:${EN
# NOTE: These objects are used by the DynamicLoader, which is always built without coverage instrumentation.
# We could allow them to be instrumented for coverage if DynamicLoader built its own copy
target_link_libraries(LibTimeZone PRIVATE NoCoverage)
if (SERENITYOS)
add_dependencies(LibTimeZone install_libc_headers)
endif()