Skip to content

Commit 757aaa3

Browse files
committed
[CMake] Set LD_LIBRARY_PATH to builder's runtime when building stdlib
In Linux. Instead of setting temporary "fallback" RUNPATH, Set LD_LIBRARY_PATH to builder's runtime when building standard library. So we don't need to strip the temporary RUNPATH when installing.
1 parent 602604b commit 757aaa3

File tree

11 files changed

+34
-110
lines changed

11 files changed

+34
-110
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ include(SwiftConfigureSDK)
794794
include(SwiftComponents)
795795
include(SwiftList)
796796
include(AddPureSwift)
797-
include(SwiftStripBuilderRpath)
797+
include(SetRPATH)
798798

799799
# Configure swift include, install, build components.
800800
swift_configure_components()

cmake/modules/AddSwift.cmake

Lines changed: 5 additions & 21 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 required_for_minimal_compiler)
443+
function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
444444
if(NOT BOOTSTRAPPING_MODE)
445445
if (SWIFT_SWIFT_PARSER)
446446
set(ASRLF_BOOTSTRAPPING_MODE "HOSTTOOLS")
@@ -550,14 +550,10 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping r
550550
target_link_directories(${target} PRIVATE ${host_lib_dir})
551551

552552
# At runtime, use swiftCore in the current toolchain.
553+
# For building stdlib, LD_LIBRARY_PATH will be set to builder's stdlib
553554
# FIXME: This assumes the ABI hasn't changed since the builder.
554555
set(swift_runtime_rpath "$ORIGIN/${relpath_to_lib_dir}/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
555556

556-
if(ASRLF_BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" AND required_for_minimal_compiler)
557-
# But before building the stdlib with the tool, use the builder libs. This should be removed in install time.
558-
list(APPEND swift_runtime_rpath "${host_lib_dir}")
559-
endif()
560-
561557
elseif(ASRLF_BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING")
562558
# At build time link against the built swift libraries from the
563559
# previous bootstrapping stage.
@@ -745,7 +741,7 @@ function(add_swift_host_library name)
745741
_set_target_prefix_and_suffix(${name} "${libkind}" "${SWIFT_HOST_VARIANT_SDK}")
746742

747743
if (ASHL_SHARED AND ASHL_HAS_SWIFT_MODULES)
748-
_add_swift_runtime_link_flags(${name} "." "" FALSE)
744+
_add_swift_runtime_link_flags(${name} "." "")
749745
endif()
750746

751747
# Set compilation and link flags.
@@ -839,7 +835,6 @@ endmacro()
839835
# add_swift_host_tool(name
840836
# [HAS_SWIFT_MODULES]
841837
# [THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY]
842-
# [REQUIRED_FOR_MINIMAL_COMPILER]
843838
#
844839
# [BOOTSTRAPPING 0|1]
845840
# [SWIFT_COMPONENT component]
@@ -855,9 +850,6 @@ endmacro()
855850
# THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
856851
# Opt-out of LLVM IR optimizations when linking ThinLTO with ld64
857852
#
858-
# REQUIRED_FOR_MINIMAL_COMPILER
859-
# Required for building standard libraries.
860-
#
861853
# BOOTSTRAPPING
862854
# Bootstrapping stage.
863855
#
@@ -870,7 +862,7 @@ endmacro()
870862
# source1 ...
871863
# Sources to add into this executable.
872864
function(add_swift_host_tool executable)
873-
set(options HAS_SWIFT_MODULES THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY REQUIRED_FOR_MINIMAL_COMPILER)
865+
set(options HAS_SWIFT_MODULES THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY)
874866
set(single_parameter_options SWIFT_COMPONENT BOOTSTRAPPING)
875867
set(multiple_parameter_options LLVM_LINK_COMPONENTS)
876868

@@ -931,7 +923,7 @@ function(add_swift_host_tool executable)
931923
endif()
932924

933925
if (ASHT_HAS_SWIFT_MODULES)
934-
_add_swift_runtime_link_flags(${executable} "../lib" "${ASHT_BOOTSTRAPPING}" "${ASHT_REQUIRED_FOR_MINIMAL_COMPILER}")
926+
_add_swift_runtime_link_flags(${executable} "../lib" "${ASHT_BOOTSTRAPPING}")
935927
endif()
936928

937929
llvm_update_compile_flags(${executable})
@@ -1007,14 +999,6 @@ function(add_swift_host_tool executable)
1007999
COMPONENT ${ASHT_SWIFT_COMPONENT}
10081000
)
10091001

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()
1017-
10181002
swift_is_installing_component(${ASHT_SWIFT_COMPONENT} is_installing)
10191003
endif()
10201004

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" "" FALSE)
116+
_add_swift_runtime_link_flags(${test_dirname} "../../lib" "")
117117
set_property(TARGET ${test_dirname} PROPERTY BUILD_WITH_INSTALL_RPATH OFF)
118118
endif()
119119
endfunction()

cmake/modules/SetRPATH.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set(SWIFT_SET_RPATH_SCRIPT_FILE "${CMAKE_CURRENT_LIST_FILE}")
2+
3+
function(swift_get_set_rpath_script_file out_var)
4+
set(${out_var} "${SWIFT_SET_RPATH_SCRIPT_FILE}" PARENT_SCOPE)
5+
endfunction()
6+
7+
# Actual RPATH_SET operation to the file.
8+
function(_swift_set_rpath_impl file new_rpath)
9+
# NOTE: RPATH_SET is not documented, and works only for ELF and XCOFF.
10+
file(RPATH_SET FILE "${file}" NEW_RPATH "${new_rpath}")
11+
endfunction()
12+
13+
# For 'cmake -P <scirpt>'.
14+
if (SWIFT_SET_RPATH_FILE AND SWIFT_SET_RPATH_NEW_RPATH)
15+
_swift_set_rpath_impl("${SWIFT_SET_RPATH_FILE}" "${SWIFT_SET_RPATH_NEW_RPATH}")
16+
endif()

cmake/modules/SwiftStripBuilderRpath.cmake

Lines changed: 0 additions & 71 deletions
This file was deleted.

cmake/modules/SwiftUtils.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ function(get_bootstrapping_swift_lib_dir bs_lib_dir bootstrapping)
107107
elseif("${bootstrapping}" STREQUAL "")
108108
get_bootstrapping_path(bs_lib_dir ${lib_dir} "1")
109109
endif()
110+
elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
111+
if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD")
112+
# Compiler's INSTALL_RPATH is set to libs in the build directory
113+
# For building stdlib, use stdlib in the builder's resource directory
114+
# because the runtime may not be built yet.
115+
# FIXME: This assumes the ABI hasn't changed since the builder.
116+
get_filename_component(swift_bin_dir ${CMAKE_Swift_COMPILER} DIRECTORY)
117+
get_filename_component(swift_dir ${swift_bin_dir} DIRECTORY)
118+
set(bs_lib_dir "${swift_dir}/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
119+
endif()
110120
endif()
111121
set(bs_lib_dir ${bs_lib_dir} PARENT_SCOPE)
112122
endfunction()

lib/CMakeLists.txt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,11 @@ if (SWIFT_SWIFT_PARSER)
5555
foreach (sharedlib ${SWIFT_SYNTAX_SHARED_LIBRARIES})
5656
set(add_origin_rpath)
5757
if(SWIFT_HOST_VARIANT_SDK STREQUAL "LINUX")
58-
get_filename_component(swift_bin_dir ${CMAKE_Swift_COMPILER} DIRECTORY)
59-
get_filename_component(swift_dir ${swift_bin_dir} DIRECTORY)
60-
set(host_lib_dir "${swift_dir}/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
61-
6258
# At runtime, use swiftCore in the current toolchain.
63-
6459
swift_get_set_rpath_script_file(setrpath_command)
6560
set(add_origin_rpath COMMAND ${CMAKE_COMMAND}
6661
"-DSWIFT_SET_RPATH_FILE=${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}"
67-
"-DSWIFT_SET_RPATH_NEW_RPATH='$$ORIGIN:$$ORIGIN/../${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}:${host_lib_dir}'"
62+
"-DSWIFT_SET_RPATH_NEW_RPATH='$$ORIGIN:$$ORIGIN/../${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}'"
6863
-P "${setrpath_command}"
6964
)
7065
endif()
@@ -87,12 +82,6 @@ if (SWIFT_SWIFT_PARSER)
8782
COMPONENT compiler
8883
)
8984

90-
swift_install_file_set_rpath(
91-
"lib${LLVM_LIBDIR_SUFFIX}/swift/host/${sharedlib}"
92-
"$ORIGIN:$ORIGIN/../${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}"
93-
compiler
94-
)
95-
9685
add_dependencies(swiftSyntaxLibraries copy_swiftSyntaxLibrary_${sharedlib})
9786
endforeach()
9887

tools/driver/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ add_swift_host_tool(swift-frontend
6565
driver.cpp
6666
SWIFT_COMPONENT compiler
6767
HAS_SWIFT_MODULES
68-
REQUIRED_FOR_MINIMAL_COMPILER
6968
)
7069
target_link_libraries(swift-frontend
7170
PUBLIC

tools/swift-compatibility-symbols/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ 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
65
)
76

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

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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
54
)
65

76
target_link_libraries(swift-def-to-strings-converter PRIVATE
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
add_swift_host_tool(swift-serialize-diagnostics
22
swift-serialize-diagnostics.cpp
33
SWIFT_COMPONENT tools
4-
REQUIRED_FOR_MINIMAL_COMPILER
54
)
65
target_link_libraries(swift-serialize-diagnostics PRIVATE
76
swiftLocalization)

0 commit comments

Comments
 (0)