Skip to content

Commit 2a2787b

Browse files
committed
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.
1 parent 9c9010e commit 2a2787b

File tree

16 files changed

+56
-69
lines changed

16 files changed

+56
-69
lines changed

cmake/modules/AddPureSwift.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ function(_set_pure_swift_link_flags name relpath_to_lib_dir)
8080
APPEND PROPERTY INSTALL_RPATH
8181
# At runtime, use swiftCore in the current toolchain.
8282
"$ORIGIN/${relpath_to_lib_dir}/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}"
83-
# But before building the stdlib with the tool, use the builder libs. This should be removed in install time.
84-
"${host_lib_dir}")
83+
)
8584

8685
endif()
8786
endfunction()

cmake/modules/AddSwift.cmake

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ function(_add_host_variant_link_flags target)
440440
endif()
441441
endfunction()
442442

443-
function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
443+
function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping required_for_minimal_compiler)
444444
if(NOT BOOTSTRAPPING_MODE)
445445
if (SWIFT_SWIFT_PARSER)
446446
set(ASRLF_BOOTSTRAPPING_MODE "HOSTTOOLS")
@@ -553,7 +553,7 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
553553
# FIXME: This assumes the ABI hasn't changed since the builder.
554554
set(swift_runtime_rpath "$ORIGIN/${relpath_to_lib_dir}/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
555555

556-
if(ASRLF_BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
556+
if(ASRLF_BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" AND required_for_minimal_compiler)
557557
# But before building the stdlib with the tool, use the builder libs. This should be removed in install time.
558558
list(APPEND swift_runtime_rpath "${host_lib_dir}")
559559
endif()
@@ -745,7 +745,7 @@ function(add_swift_host_library name)
745745
_set_target_prefix_and_suffix(${name} "${libkind}" "${SWIFT_HOST_VARIANT_SDK}")
746746

747747
if (ASHL_SHARED AND ASHL_HAS_SWIFT_MODULES)
748-
_add_swift_runtime_link_flags(${name} "." "")
748+
_add_swift_runtime_link_flags(${name} "." "" FALSE)
749749
endif()
750750

751751
# Set compilation and link flags.
@@ -833,8 +833,44 @@ macro(add_swift_lib_subdirectory name)
833833
add_llvm_subdirectory(SWIFT LIB ${name})
834834
endmacro()
835835

836+
# Add a new Swift host executable.
837+
#
838+
# Usage:
839+
# add_swift_host_tool(name
840+
# [HAS_SWIFT_MODULES]
841+
# [THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY]
842+
# [REQUIRED_FOR_MINIMAL_COMPILER]
843+
#
844+
# [BOOTSTRAPPING 0|1]
845+
# [SWIFT_COMPONENT component]
846+
# [LLVM_LINK_COMPONENTS comp1 ...]
847+
# source1 [source2 source3 ...])
848+
#
849+
# name
850+
# Name of the executable (e.g., swift-frontend).
851+
#
852+
# HAS_SWIFT_MODULES
853+
# Whether to link with SwiftCompilerSources library
854+
#
855+
# THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
856+
# Opt-out of LLVM IR optimizations when linking ThinLTO with ld64
857+
#
858+
# REQUIRED_FOR_MINIMAL_COMPILER
859+
# Required for building standard libraries.
860+
#
861+
# BOOTSTRAPPING
862+
# Bootstrapping stage.
863+
#
864+
# SWIFT_COMPONENT
865+
# Installation component where this tool belongs to.
866+
#
867+
# LLVM_LINK_COMPONENTS
868+
# LLVM components this library depends on.
869+
#
870+
# source1 ...
871+
# Sources to add into this executable.
836872
function(add_swift_host_tool executable)
837-
set(options HAS_SWIFT_MODULES THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY)
873+
set(options HAS_SWIFT_MODULES THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY REQUIRED_FOR_MINIMAL_COMPILER)
838874
set(single_parameter_options SWIFT_COMPONENT BOOTSTRAPPING)
839875
set(multiple_parameter_options LLVM_LINK_COMPONENTS)
840876

@@ -895,7 +931,7 @@ function(add_swift_host_tool executable)
895931
endif()
896932

897933
if (ASHT_HAS_SWIFT_MODULES)
898-
_add_swift_runtime_link_flags(${executable} "../lib" "${ASHT_BOOTSTRAPPING}")
934+
_add_swift_runtime_link_flags(${executable} "../lib" "${ASHT_BOOTSTRAPPING}" "${ASHT_REQUIRED_FOR_MINIMAL_COMPILER}")
899935
endif()
900936

901937
llvm_update_compile_flags(${executable})
@@ -971,11 +1007,13 @@ function(add_swift_host_tool executable)
9711007
COMPONENT ${ASHT_SWIFT_COMPONENT}
9721008
)
9731009

974-
swift_install_strip_builder_rpath(
975-
TARGETS ${executable}
976-
DESTINATION bin
977-
COMPONENT ${ASHT_SWIFT_COMPONENT}
978-
)
1010+
if (ASHT_REQUIRED_FOR_MINIMAL_COMPILER)
1011+
swift_install_strip_builder_rpath(
1012+
TARGETS ${executable}
1013+
DESTINATION bin
1014+
COMPONENT ${ASHT_SWIFT_COMPONENT}
1015+
)
1016+
endif()
9791017

9801018
swift_is_installing_component(${ASHT_SWIFT_COMPONENT} is_installing)
9811019
endif()

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function(add_swift_unittest test_dirname)
113113

114114
if (SWIFT_SWIFT_PARSER AND NOT ASU_IS_TARGET_TEST)
115115
# Link to stdlib the compiler uses.
116-
_add_swift_runtime_link_flags(${test_dirname} "../../lib" "")
116+
_add_swift_runtime_link_flags(${test_dirname} "../../lib" "" FALSE)
117117
set_property(TARGET ${test_dirname} PROPERTY BUILD_WITH_INSTALL_RPATH OFF)
118118
endif()
119119
endfunction()

lib/Macros/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ function(add_swift_macro_library name)
6767
DESTINATION "${destination_dir}"
6868
COMPONENT compiler)
6969

70-
swift_install_strip_builder_rpath(
71-
TARGETS ${name}
72-
DESTINATION "${destination_dir}"
73-
COMPONENT compiler
74-
)
75-
7670
# Export this macro plugin target.
7771
set_property(GLOBAL APPEND PROPERTY SWIFT_MACRO_PLUGINS ${name})
7872
endfunction()

lib/SwiftDemangle/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,3 @@ swift_install_in_component(TARGETS swiftDemangle
1717
ARCHIVE
1818
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
1919
COMPONENT compiler)
20-
21-
22-
swift_install_strip_builder_rpath(
23-
TARGETS swiftDemangle
24-
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
25-
COMPONENT compiler
26-
)

tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,6 @@ macro(add_sourcekit_library name)
303303
DESTINATION "bin"
304304
COMPONENT "${SOURCEKITLIB_INSTALL_IN_COMPONENT}")
305305

306-
if(SOURCEKITLIB_SHARED)
307-
swift_install_strip_builder_rpath(
308-
TARGETS ${name}
309-
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
310-
COMPONENT "${SOURCEKITLIB_INSTALL_IN_COMPONENT}"
311-
)
312-
endif()
313-
314306
swift_install_in_component(FILES ${SOURCEKITLIB_HEADERS}
315307
DESTINATION "include/SourceKit"
316308
COMPONENT "${SOURCEKITLIB_INSTALL_IN_COMPONENT}")

tools/SourceKit/tools/complete-test/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,3 @@ endif()
2727
add_dependencies(tools complete-test)
2828
swift_install_in_component(TARGETS complete-test
2929
RUNTIME DESTINATION bin COMPONENT tools)
30-
31-
swift_install_strip_builder_rpath(
32-
TARGETS complete-test
33-
DESTINATION bin
34-
COMPONENT tools
35-
)

tools/SourceKit/tools/sourcekitd-repl/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,3 @@ endif()
2929
add_dependencies(tools sourcekitd-repl)
3030
swift_install_in_component(TARGETS sourcekitd-repl
3131
RUNTIME DESTINATION bin COMPONENT tools)
32-
33-
swift_install_strip_builder_rpath(
34-
TARGETS sourcekitd-repl
35-
DESTINATION bin
36-
COMPONENT tools
37-
)

tools/SourceKit/tools/sourcekitd-test/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,3 @@ endif()
3939
add_dependencies(tools sourcekitd-test)
4040
swift_install_in_component(TARGETS sourcekitd-test
4141
RUNTIME DESTINATION bin COMPONENT tools)
42-
43-
swift_install_strip_builder_rpath(
44-
TARGETS sourcekitd-test
45-
DESTINATION bin
46-
COMPONENT tools
47-
)

tools/driver/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ if(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
2626
HAS_SWIFT_MODULES
2727
BOOTSTRAPPING 0
2828
THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
29+
REQUIRED_FOR_MINIMAL_COMPILER
2930
)
3031
target_link_libraries(swift-frontend-bootstrapping0
3132
PRIVATE
@@ -47,6 +48,7 @@ if(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
4748
HAS_SWIFT_MODULES
4849
BOOTSTRAPPING 1
4950
THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
51+
REQUIRED_FOR_MINIMAL_COMPILER
5052
)
5153
target_link_libraries(swift-frontend-bootstrapping1
5254
PRIVATE
@@ -65,6 +67,7 @@ add_swift_host_tool(swift-frontend
6567
driver.cpp
6668
SWIFT_COMPONENT compiler
6769
HAS_SWIFT_MODULES
70+
REQUIRED_FOR_MINIMAL_COMPILER
6871
)
6972
target_link_libraries(swift-frontend
7073
PUBLIC

tools/libStaticMirror/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,3 @@ swift_install_in_component(TARGETS libStaticMirror
3737
swift_install_in_component(DIRECTORY "${SWIFT_MAIN_INCLUDE_DIR}/swift-c/StaticMirror/"
3838
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${SWIFT_SCAN_LIB_NAME}"
3939
COMPONENT static-mirror-lib)
40-
41-
swift_install_strip_builder_rpath(
42-
TARGETS libStaticMirror
43-
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}"
44-
COMPONENT static-mirror-lib
45-
)

tools/libSwiftScan/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ else()
6969
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host" COMPONENT compiler
7070
RUNTIME DESTINATION "bin" COMPONENT compiler)
7171

72-
swift_install_strip_builder_rpath(
73-
TARGETS libSwiftScan
74-
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host"
75-
COMPONENT compiler
76-
)
77-
7872
# Create a symlink to previously-used path of 'lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}'
7973
# to the new location under 'lib/swift/host' for clients of the legacy path.
8074
if(EXISTS ${LLVM_CMAKE_DIR}/LLVMInstallSymlink.cmake)

tools/swift-compatibility-symbols/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ add_swift_host_tool(swift-compatibility-symbols
22
swift-compatibility-symbols.cpp
33
LLVM_LINK_COMPONENTS support
44
SWIFT_COMPONENT tools
5+
REQUIRED_FOR_MINIMAL_COMPILER
56
)
67

78
set(syms_file "${CMAKE_BINARY_DIR}/share/swift/compatibility-symbols")

tools/swift-def-to-strings-converter/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
add_swift_host_tool(swift-def-to-strings-converter
22
swift-def-to-strings-converter.cpp
33
SWIFT_COMPONENT tools
4+
REQUIRED_FOR_MINIMAL_COMPILER
45
)
56

67
target_link_libraries(swift-def-to-strings-converter PRIVATE

tools/swift-plugin-server/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,4 @@ if (SWIFT_SWIFT_PARSER)
3030
DESTINATION bin
3131
COMPONENT compiler
3232
)
33-
swift_install_strip_builder_rpath(
34-
TARGETS swift-plugin-server
35-
DESTINATION bin
36-
COMPONENT compiler
37-
)
3833
endif()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
add_swift_host_tool(swift-serialize-diagnostics
22
swift-serialize-diagnostics.cpp
33
SWIFT_COMPONENT tools
4+
REQUIRED_FOR_MINIMAL_COMPILER
45
)
56
target_link_libraries(swift-serialize-diagnostics PRIVATE
67
swiftLocalization)

0 commit comments

Comments
 (0)