Skip to content

Commit 24e7403

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. (cherry picked from commit 757aaa3) (cherry picked from commit f5445f4)
1 parent a5d05ea commit 24e7403

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
@@ -799,7 +799,7 @@ include(SwiftConfigureSDK)
799799
include(SwiftComponents)
800800
include(SwiftList)
801801
include(AddPureSwift)
802-
include(SwiftStripBuilderRpath)
802+
include(SetRPATH)
803803

804804
# Configure swift include, install, build components.
805805
swift_configure_components()

cmake/modules/AddSwift.cmake

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ function(_add_host_variant_link_flags target)
437437
endif()
438438
endfunction()
439439

440-
function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping required_for_minimal_compiler)
440+
function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
441441
if(NOT BOOTSTRAPPING_MODE)
442442
if (SWIFT_SWIFT_PARSER)
443443
set(ASRLF_BOOTSTRAPPING_MODE "HOSTTOOLS")
@@ -547,14 +547,10 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping r
547547
target_link_directories(${target} PRIVATE ${host_lib_dir})
548548

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

553-
if(ASRLF_BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" AND required_for_minimal_compiler)
554-
# But before building the stdlib with the tool, use the builder libs. This should be removed in install time.
555-
list(APPEND swift_runtime_rpath "${host_lib_dir}")
556-
endif()
557-
558554
elseif(ASRLF_BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING")
559555
# At build time link against the built swift libraries from the
560556
# previous bootstrapping stage.
@@ -742,7 +738,7 @@ function(add_swift_host_library name)
742738
_set_target_prefix_and_suffix(${name} "${libkind}" "${SWIFT_HOST_VARIANT_SDK}")
743739

744740
if (ASHL_SHARED AND ASHL_HAS_SWIFT_MODULES)
745-
_add_swift_runtime_link_flags(${name} "." "" FALSE)
741+
_add_swift_runtime_link_flags(${name} "." "")
746742
endif()
747743

748744
# Set compilation and link flags.
@@ -836,7 +832,6 @@ endmacro()
836832
# add_swift_host_tool(name
837833
# [HAS_SWIFT_MODULES]
838834
# [THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY]
839-
# [REQUIRED_FOR_MINIMAL_COMPILER]
840835
#
841836
# [BOOTSTRAPPING 0|1]
842837
# [SWIFT_COMPONENT component]
@@ -852,9 +847,6 @@ endmacro()
852847
# THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
853848
# Opt-out of LLVM IR optimizations when linking ThinLTO with ld64
854849
#
855-
# REQUIRED_FOR_MINIMAL_COMPILER
856-
# Required for building standard libraries.
857-
#
858850
# BOOTSTRAPPING
859851
# Bootstrapping stage.
860852
#
@@ -867,7 +859,7 @@ endmacro()
867859
# source1 ...
868860
# Sources to add into this executable.
869861
function(add_swift_host_tool executable)
870-
set(options HAS_SWIFT_MODULES THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY REQUIRED_FOR_MINIMAL_COMPILER)
862+
set(options HAS_SWIFT_MODULES THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY)
871863
set(single_parameter_options SWIFT_COMPONENT BOOTSTRAPPING)
872864
set(multiple_parameter_options LLVM_LINK_COMPONENTS)
873865

@@ -928,7 +920,7 @@ function(add_swift_host_tool executable)
928920
endif()
929921

930922
if (ASHT_HAS_SWIFT_MODULES)
931-
_add_swift_runtime_link_flags(${executable} "../lib" "${ASHT_BOOTSTRAPPING}" "${ASHT_REQUIRED_FOR_MINIMAL_COMPILER}")
923+
_add_swift_runtime_link_flags(${executable} "../lib" "${ASHT_BOOTSTRAPPING}")
932924
endif()
933925

934926
llvm_update_compile_flags(${executable})
@@ -1004,14 +996,6 @@ function(add_swift_host_tool executable)
1004996
COMPONENT ${ASHT_SWIFT_COMPONENT}
1005997
)
1006998

1007-
if (ASHT_REQUIRED_FOR_MINIMAL_COMPILER)
1008-
swift_install_strip_builder_rpath(
1009-
TARGETS ${executable}
1010-
DESTINATION bin
1011-
COMPONENT ${ASHT_SWIFT_COMPONENT}
1012-
)
1013-
endif()
1014-
1015999
swift_is_installing_component(${ASHT_SWIFT_COMPONENT} is_installing)
10161000
endif()
10171001

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
@@ -58,16 +58,11 @@ if (SWIFT_SWIFT_PARSER)
5858
foreach (sharedlib ${SWIFT_SYNTAX_SHARED_LIBRARIES})
5959
set(add_origin_rpath)
6060
if(SWIFT_HOST_VARIANT_SDK STREQUAL "LINUX")
61-
get_filename_component(swift_bin_dir ${CMAKE_Swift_COMPILER} DIRECTORY)
62-
get_filename_component(swift_dir ${swift_bin_dir} DIRECTORY)
63-
set(host_lib_dir "${swift_dir}/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
64-
6561
# At runtime, use swiftCore in the current toolchain.
66-
6762
swift_get_set_rpath_script_file(setrpath_command)
6863
set(add_origin_rpath COMMAND ${CMAKE_COMMAND}
6964
"-DSWIFT_SET_RPATH_FILE=${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}"
70-
"-DSWIFT_SET_RPATH_NEW_RPATH='$$ORIGIN:$$ORIGIN/../${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}:${host_lib_dir}'"
65+
"-DSWIFT_SET_RPATH_NEW_RPATH='$$ORIGIN:$$ORIGIN/../${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}'"
7166
-P "${setrpath_command}"
7267
)
7368
endif()
@@ -90,12 +85,6 @@ if (SWIFT_SWIFT_PARSER)
9085
COMPONENT compiler
9186
)
9287

93-
swift_install_file_set_rpath(
94-
"lib${LLVM_LIBDIR_SUFFIX}/swift/host/${sharedlib}"
95-
"$ORIGIN:$ORIGIN/../${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}"
96-
compiler
97-
)
98-
9988
add_dependencies(swiftSyntaxLibraries copy_swiftSyntaxLibrary_${sharedlib})
10089
endforeach()
10190

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

0 commit comments

Comments
 (0)