Avoid adding redundant temporary RUNPATH to builder's stdlib

Many shared libs and executables are only run after stdlib/runtime are
built. They don't need to link with builders stdlib at all.
This commit is contained in:
Rintaro Ishizaki
2023-08-24 22:54:47 +00:00
parent 9c9010e5b7
commit 2a2787b2d0
16 changed files with 56 additions and 69 deletions

View File

@@ -80,8 +80,7 @@ function(_set_pure_swift_link_flags name relpath_to_lib_dir)
APPEND PROPERTY INSTALL_RPATH
# At runtime, use swiftCore in the current toolchain.
"$ORIGIN/${relpath_to_lib_dir}/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}"
# But before building the stdlib with the tool, use the builder libs. This should be removed in install time.
"${host_lib_dir}")
)
endif()
endfunction()

View File

@@ -440,7 +440,7 @@ function(_add_host_variant_link_flags target)
endif()
endfunction()
function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping required_for_minimal_compiler)
if(NOT BOOTSTRAPPING_MODE)
if (SWIFT_SWIFT_PARSER)
set(ASRLF_BOOTSTRAPPING_MODE "HOSTTOOLS")
@@ -553,7 +553,7 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
# FIXME: This assumes the ABI hasn't changed since the builder.
set(swift_runtime_rpath "$ORIGIN/${relpath_to_lib_dir}/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
if(ASRLF_BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
if(ASRLF_BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" AND required_for_minimal_compiler)
# But before building the stdlib with the tool, use the builder libs. This should be removed in install time.
list(APPEND swift_runtime_rpath "${host_lib_dir}")
endif()
@@ -745,7 +745,7 @@ function(add_swift_host_library name)
_set_target_prefix_and_suffix(${name} "${libkind}" "${SWIFT_HOST_VARIANT_SDK}")
if (ASHL_SHARED AND ASHL_HAS_SWIFT_MODULES)
_add_swift_runtime_link_flags(${name} "." "")
_add_swift_runtime_link_flags(${name} "." "" FALSE)
endif()
# Set compilation and link flags.
@@ -833,8 +833,44 @@ macro(add_swift_lib_subdirectory name)
add_llvm_subdirectory(SWIFT LIB ${name})
endmacro()
# Add a new Swift host executable.
#
# Usage:
# add_swift_host_tool(name
# [HAS_SWIFT_MODULES]
# [THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY]
# [REQUIRED_FOR_MINIMAL_COMPILER]
#
# [BOOTSTRAPPING 0|1]
# [SWIFT_COMPONENT component]
# [LLVM_LINK_COMPONENTS comp1 ...]
# source1 [source2 source3 ...])
#
# name
# Name of the executable (e.g., swift-frontend).
#
# HAS_SWIFT_MODULES
# Whether to link with SwiftCompilerSources library
#
# THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
# Opt-out of LLVM IR optimizations when linking ThinLTO with ld64
#
# REQUIRED_FOR_MINIMAL_COMPILER
# Required for building standard libraries.
#
# BOOTSTRAPPING
# Bootstrapping stage.
#
# SWIFT_COMPONENT
# Installation component where this tool belongs to.
#
# LLVM_LINK_COMPONENTS
# LLVM components this library depends on.
#
# source1 ...
# Sources to add into this executable.
function(add_swift_host_tool executable)
set(options HAS_SWIFT_MODULES THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY)
set(options HAS_SWIFT_MODULES THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY REQUIRED_FOR_MINIMAL_COMPILER)
set(single_parameter_options SWIFT_COMPONENT BOOTSTRAPPING)
set(multiple_parameter_options LLVM_LINK_COMPONENTS)
@@ -895,7 +931,7 @@ function(add_swift_host_tool executable)
endif()
if (ASHT_HAS_SWIFT_MODULES)
_add_swift_runtime_link_flags(${executable} "../lib" "${ASHT_BOOTSTRAPPING}")
_add_swift_runtime_link_flags(${executable} "../lib" "${ASHT_BOOTSTRAPPING}" "${ASHT_REQUIRED_FOR_MINIMAL_COMPILER}")
endif()
llvm_update_compile_flags(${executable})
@@ -971,11 +1007,13 @@ function(add_swift_host_tool executable)
COMPONENT ${ASHT_SWIFT_COMPONENT}
)
swift_install_strip_builder_rpath(
TARGETS ${executable}
DESTINATION bin
COMPONENT ${ASHT_SWIFT_COMPONENT}
)
if (ASHT_REQUIRED_FOR_MINIMAL_COMPILER)
swift_install_strip_builder_rpath(
TARGETS ${executable}
DESTINATION bin
COMPONENT ${ASHT_SWIFT_COMPONENT}
)
endif()
swift_is_installing_component(${ASHT_SWIFT_COMPONENT} is_installing)
endif()

View File

@@ -113,7 +113,7 @@ function(add_swift_unittest test_dirname)
if (SWIFT_SWIFT_PARSER AND NOT ASU_IS_TARGET_TEST)
# Link to stdlib the compiler uses.
_add_swift_runtime_link_flags(${test_dirname} "../../lib" "")
_add_swift_runtime_link_flags(${test_dirname} "../../lib" "" FALSE)
set_property(TARGET ${test_dirname} PROPERTY BUILD_WITH_INSTALL_RPATH OFF)
endif()
endfunction()

View File

@@ -67,12 +67,6 @@ function(add_swift_macro_library name)
DESTINATION "${destination_dir}"
COMPONENT compiler)
swift_install_strip_builder_rpath(
TARGETS ${name}
DESTINATION "${destination_dir}"
COMPONENT compiler
)
# Export this macro plugin target.
set_property(GLOBAL APPEND PROPERTY SWIFT_MACRO_PLUGINS ${name})
endfunction()

View File

@@ -17,10 +17,3 @@ swift_install_in_component(TARGETS swiftDemangle
ARCHIVE
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
COMPONENT compiler)
swift_install_strip_builder_rpath(
TARGETS swiftDemangle
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
COMPONENT compiler
)

View File

@@ -303,14 +303,6 @@ macro(add_sourcekit_library name)
DESTINATION "bin"
COMPONENT "${SOURCEKITLIB_INSTALL_IN_COMPONENT}")
if(SOURCEKITLIB_SHARED)
swift_install_strip_builder_rpath(
TARGETS ${name}
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
COMPONENT "${SOURCEKITLIB_INSTALL_IN_COMPONENT}"
)
endif()
swift_install_in_component(FILES ${SOURCEKITLIB_HEADERS}
DESTINATION "include/SourceKit"
COMPONENT "${SOURCEKITLIB_INSTALL_IN_COMPONENT}")

View File

@@ -27,9 +27,3 @@ endif()
add_dependencies(tools complete-test)
swift_install_in_component(TARGETS complete-test
RUNTIME DESTINATION bin COMPONENT tools)
swift_install_strip_builder_rpath(
TARGETS complete-test
DESTINATION bin
COMPONENT tools
)

View File

@@ -29,9 +29,3 @@ endif()
add_dependencies(tools sourcekitd-repl)
swift_install_in_component(TARGETS sourcekitd-repl
RUNTIME DESTINATION bin COMPONENT tools)
swift_install_strip_builder_rpath(
TARGETS sourcekitd-repl
DESTINATION bin
COMPONENT tools
)

View File

@@ -39,9 +39,3 @@ endif()
add_dependencies(tools sourcekitd-test)
swift_install_in_component(TARGETS sourcekitd-test
RUNTIME DESTINATION bin COMPONENT tools)
swift_install_strip_builder_rpath(
TARGETS sourcekitd-test
DESTINATION bin
COMPONENT tools
)

View File

@@ -26,6 +26,7 @@ if(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
HAS_SWIFT_MODULES
BOOTSTRAPPING 0
THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
REQUIRED_FOR_MINIMAL_COMPILER
)
target_link_libraries(swift-frontend-bootstrapping0
PRIVATE
@@ -47,6 +48,7 @@ if(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
HAS_SWIFT_MODULES
BOOTSTRAPPING 1
THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
REQUIRED_FOR_MINIMAL_COMPILER
)
target_link_libraries(swift-frontend-bootstrapping1
PRIVATE
@@ -65,6 +67,7 @@ add_swift_host_tool(swift-frontend
driver.cpp
SWIFT_COMPONENT compiler
HAS_SWIFT_MODULES
REQUIRED_FOR_MINIMAL_COMPILER
)
target_link_libraries(swift-frontend
PUBLIC

View File

@@ -37,9 +37,3 @@ swift_install_in_component(TARGETS libStaticMirror
swift_install_in_component(DIRECTORY "${SWIFT_MAIN_INCLUDE_DIR}/swift-c/StaticMirror/"
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${SWIFT_SCAN_LIB_NAME}"
COMPONENT static-mirror-lib)
swift_install_strip_builder_rpath(
TARGETS libStaticMirror
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}"
COMPONENT static-mirror-lib
)

View File

@@ -69,12 +69,6 @@ else()
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host" COMPONENT compiler
RUNTIME DESTINATION "bin" COMPONENT compiler)
swift_install_strip_builder_rpath(
TARGETS libSwiftScan
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host"
COMPONENT compiler
)
# Create a symlink to previously-used path of 'lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}'
# to the new location under 'lib/swift/host' for clients of the legacy path.
if(EXISTS ${LLVM_CMAKE_DIR}/LLVMInstallSymlink.cmake)

View File

@@ -2,6 +2,7 @@ add_swift_host_tool(swift-compatibility-symbols
swift-compatibility-symbols.cpp
LLVM_LINK_COMPONENTS support
SWIFT_COMPONENT tools
REQUIRED_FOR_MINIMAL_COMPILER
)
set(syms_file "${CMAKE_BINARY_DIR}/share/swift/compatibility-symbols")

View File

@@ -1,6 +1,7 @@
add_swift_host_tool(swift-def-to-strings-converter
swift-def-to-strings-converter.cpp
SWIFT_COMPONENT tools
REQUIRED_FOR_MINIMAL_COMPILER
)
target_link_libraries(swift-def-to-strings-converter PRIVATE

View File

@@ -30,9 +30,4 @@ if (SWIFT_SWIFT_PARSER)
DESTINATION bin
COMPONENT compiler
)
swift_install_strip_builder_rpath(
TARGETS swift-plugin-server
DESTINATION bin
COMPONENT compiler
)
endif()

View File

@@ -1,6 +1,7 @@
add_swift_host_tool(swift-serialize-diagnostics
swift-serialize-diagnostics.cpp
SWIFT_COMPONENT tools
REQUIRED_FOR_MINIMAL_COMPILER
)
target_link_libraries(swift-serialize-diagnostics PRIVATE
swiftLocalization)