Skip to content

Commit 035b385

Browse files
committed
Re-add EXTRA_RPATHS CMake logic.
This logic is used for the TensorFlow module. It was somehow lost in the merge. I marked all additions within SWIFT_ENABLE_TENSORFLOW comments.
1 parent ed83da5 commit 035b385

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,9 @@ endfunction()
593593
# [LINK_FLAGS flag1...]
594594
# [API_NOTES_NON_OVERLAY]
595595
# [FILE_DEPENDS target1 ...]
596+
# SWIFT_ENABLE_TENSORFLOW
597+
# [EXTRA_RPATHS rpath1 ...]
598+
# END SWIFT_ENABLE_TENSORFLOW
596599
# [DONT_EMBED_BITCODE]
597600
# [IS_STDLIB]
598601
# [FORCE_BUILD_OPTIMIZED]
@@ -652,6 +655,11 @@ endfunction()
652655
# FILE_DEPENDS
653656
# Additional files this library depends on.
654657
#
658+
# SWIFT_ENABLE_TENSORFLOW
659+
# EXTRA_RPATHS
660+
# List of directories to add to this library's RPATH.
661+
# END SWIFT_ENABLE_TENSORFLOW
662+
#
655663
# DONT_EMBED_BITCODE
656664
# Don't embed LLVM bitcode in this target, even if it is enabled globally.
657665
#
@@ -695,6 +703,9 @@ function(_add_swift_library_single target name)
695703
C_COMPILE_FLAGS
696704
DEPENDS
697705
FILE_DEPENDS
706+
# SWIFT_ENABLE_TENSORFLOW
707+
EXTRA_RPATHS
708+
# END SWIFT_ENABLE_TENSORFLOW
698709
FRAMEWORK_DEPENDS
699710
FRAMEWORK_DEPENDS_WEAK
700711
INCORPORATE_OBJECT_LIBRARIES
@@ -1031,6 +1042,28 @@ function(_add_swift_library_single target name)
10311042
INSTALL_RPATH "$ORIGIN:/usr/lib/swift/cygwin")
10321043
endif()
10331044

1045+
# SWIFT_ENABLE_TENSORFLOW
1046+
# Hande extra RPATHs.
1047+
set(local_rpath "")
1048+
if("${SWIFTLIB_SINGLE_SDK}" STREQUAL "LINUX" AND NOT "${SWIFTLIB_SINGLE_SDK}" STREQUAL "ANDROID")
1049+
set(local_rpath "$ORIGIN:/usr/lib/swift/linux")
1050+
elseif("${SWIFTLIB_SINGLE_SDK}" STREQUAL "CYGWIN")
1051+
set(local_rpath "$ORIGIN:/usr/lib/swift/cygwin")
1052+
endif()
1053+
foreach(rpath_element ${SWIFTLIB_SINGLE_EXTRA_RPATHS})
1054+
if("${local_rpath}" STREQUAL "")
1055+
set(local_rpath "${rpath_element}")
1056+
else()
1057+
set(local_rpath "${local_rpath}:${rpath_element}")
1058+
endif()
1059+
endforeach()
1060+
if(NOT "${local_rpath}" STREQUAL "")
1061+
set_target_properties("${target}"
1062+
PROPERTIES
1063+
INSTALL_RPATH "${local_rpath}")
1064+
endif()
1065+
# END SWIFT_ENABLE_TENSORFLOW
1066+
10341067
set_target_properties("${target}" PROPERTIES BUILD_WITH_INSTALL_RPATH YES)
10351068
set_target_properties("${target}" PROPERTIES FOLDER "Swift libraries")
10361069

@@ -2131,6 +2164,20 @@ function(_add_swift_executable_single name)
21312164
"-Xlinker" "@executable_path/../lib/swift/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}")
21322165
endif()
21332166

2167+
# SWIFT_ENABLE_TENSORFLOW
2168+
set(swift_relative_library_path "../lib/swift/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}")
2169+
is_darwin_based_sdk("${SWIFTEXE_SINGLE_SDK}" IS_DARWIN)
2170+
# NOTE: Adding "${SWIFTLIB_DIR}/linux" to the rpath is a hack solely for
2171+
# working around tests like Driver/linker.swift which copy/hard link Swift
2172+
# executables to different directories without also copying the "libs"
2173+
# directory. A more robust solution should be found.
2174+
if("${SWIFTEXE_SINGLE_SDK}" STREQUAL "LINUX" AND NOT "${SWIFTEXE_SINGLE_SDK}" STREQUAL "ANDROID")
2175+
set(local_rpath "$ORIGIN:$ORIGIN/${swift_relative_library_path}:${SWIFTLIB_DIR}/linux:/usr/lib/swift/linux")
2176+
elseif("${SWIFTEXE_SINGLE_SDK}" STREQUAL "CYGWIN")
2177+
set(local_rpath "$ORIGIN:$ORIGIN/${swift_relative_library_path}:${SWIFTLIB_DIR}/cygwin:/usr/lib/swift/cygwin")
2178+
endif()
2179+
# END SWIFT_ENABLE_TENSORFLOW
2180+
21342181
# Find the names of dependency library targets.
21352182
#
21362183
# We don't add the ${ARCH} to the target suffix because we want to link
@@ -2192,6 +2239,13 @@ function(_add_swift_executable_single name)
21922239

21932240
set_target_properties(${name}
21942241
PROPERTIES FOLDER "Swift executables")
2242+
2243+
# SWIFT_ENABLE_TENSORFLOW
2244+
if(NOT "${local_rpath}" STREQUAL "")
2245+
set_target_properties("${name}" PROPERTIES INSTALL_RPATH "${local_rpath}")
2246+
endif()
2247+
set_target_properties("${name}" PROPERTIES BUILD_WITH_INSTALL_RPATH YES)
2248+
# END SWIFT_ENABLE_TENSORFLOW
21952249
endfunction()
21962250

21972251
# Add an executable for each target variant. Executables are given suffixes

stdlib/public/TensorFlow/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@ add_swift_target_library(swiftTensorFlow ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_
8787
SWIFT_COMPILE_FLAGS "${swift_stdlib_compile_flags}"
8888
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
8989
INSTALL_IN_COMPONENT stdlib
90-
EXTRA_RPATH "${SWIFT_TENSORFLOW_TARGET_LIB_DIR}")
90+
EXTRA_RPATHS "${SWIFT_TENSORFLOW_TARGET_LIB_DIR}")

0 commit comments

Comments
 (0)