Skip to content

Commit c0c93fa

Browse files
committed
[cmake] Copy Dispatch to the SDK subdir on host.
We have two directories for Swift libraries, * `SWIFT_SDK_<platform>_LIB_SUBDIR`, a.k.a., the SDK subdir, a.k.a., `swift-<platform>-<arch>/lib/swift/<platform>`, and * `SWIFTLIB_SINGLE_SUBDIR`, a.k.a., `swift-<platform>-<arch>/lib/swift/<platform>/<arch>`. Through the Swift build, libraries are emitted to both `.../lib/swift/<platform>` and `.../lib/swift/<platform>/<arch>`. However, when building toolchains, only `.../lib/swift/<platform>/` is populated with libraries. None of this normally isn't a problem; the Swift libraries do not have inherent interdependencies. This however changes with Concurrency: Concurrency has an implicit dependency on libdispatch. When Swift is built, we have two copies of `libswift_Concurrency.so`: one in `.../lib/swift/<platform>` and one in `.../lib/swift/<platform>/<arch>`. Prior to this commit, we unconditionally copy `libdispatch.so` and `libBlocksRuntime.so` to only _one_ place -- that is, `.../lib/swift/<platform>/<arch>`. swiftc emits binaries on ELF systems with an rpath of `.../lib/swift/<platform>`. These binaries implicitly import Concurrency, so they link against `libswift_Concurrency.so` (whether they use Concurrency features or not). The library's `$ORIGIN` is searched to find `libdispatch.so`. Now, nothing breaks on Linux because there the loader, when given an rpath, searches both `.../lib/swift/<platform>` and `.../lib/swift/<platform>/<arch>` even though the rpath only specifies one directory.. However, on other platforms, only the given rpath is searched. `libdispatch.so` does not reside next to `libswift_Concurrency.so` because it has been copied to `.../lib/swift/<platform>/<arch>`; not in the rpath. There are a few ways to solve this: change the way rpaths are configured, only emit libraries into one place, copy `libdispatch.so` only to the path matching the rpath, or copy `libdispatch.so` wherever `libswift_Concurrency.so` is copied, Because the toolchain file layout is different to the file layout when only Swift is built, hacking the rpath is brittle. Presumably, the reason why we have a `libswift_Concurrency.so` residing in two places is to support builds where multiple architectures are supported in the one build directory, so we cannot just copy `libdispatch.so` _only_ to `.../lib/swift/<platform>`. Ultimately, We need to ensure that every instance where `libswift_Concurrency.so` can be used has `libdispatch.so` residing next to it, which we do here. Note that this implicit dependency resolution would not happen unless we added a `-ldispatch` flag to make this all work, but other platforms are instaed using `$ORIGIN` to get the search to work properly, so we also do this for OpenBSD in this commit.
1 parent e65ae80 commit c0c93fa

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

cmake/modules/Libdispatch.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ foreach(sdk ${DISPATCH_SDKS})
110110
${CMAKE_COMMAND} -E copy
111111
<INSTALL_DIR>/${LIBDISPATCH_RUNTIME_DIR}/${SWIFT_SDK_${sdk}_SHARED_LIBRARY_PREFIX}BlocksRuntime${SWIFT_SDK_${sdk}_SHARED_LIBRARY_SUFFIX}
112112
${SWIFTLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}/${SWIFT_SDK_${sdk}_SHARED_LIBRARY_PREFIX}BlocksRuntime${SWIFT_SDK_${sdk}_SHARED_LIBRARY_SUFFIX}
113+
COMMAND
114+
${CMAKE_COMMAND} -E copy
115+
<INSTALL_DIR>/${LIBDISPATCH_RUNTIME_DIR}/${SWIFT_SDK_${sdk}_SHARED_LIBRARY_PREFIX}dispatch${SWIFT_SDK_${sdk}_SHARED_LIBRARY_SUFFIX}
116+
${SWIFTLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${SWIFT_SDK_${sdk}_SHARED_LIBRARY_PREFIX}dispatch${SWIFT_SDK_${sdk}_SHARED_LIBRARY_SUFFIX}
117+
COMMAND
118+
${CMAKE_COMMAND} -E copy
119+
<INSTALL_DIR>/${LIBDISPATCH_RUNTIME_DIR}/${SWIFT_SDK_${sdk}_SHARED_LIBRARY_PREFIX}BlocksRuntime${SWIFT_SDK_${sdk}_SHARED_LIBRARY_SUFFIX}
120+
${SWIFTLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${SWIFT_SDK_${sdk}_SHARED_LIBRARY_PREFIX}BlocksRuntime${SWIFT_SDK_${sdk}_SHARED_LIBRARY_SUFFIX}
113121
STEP_TARGETS
114122
install
115123
BUILD_BYPRODUCTS

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,10 @@ function(_add_swift_target_library_single target name)
995995
PROPERTIES
996996
INSTALL_RPATH "$ORIGIN")
997997
endif()
998+
elseif("${SWIFTLIB_SINGLE_SDK}" STREQUAL "OPENBSD")
999+
set_target_properties("${target}"
1000+
PROPERTIES
1001+
INSTALL_RPATH "$ORIGIN")
9981002
endif()
9991003

10001004
set_target_properties("${target}" PROPERTIES BUILD_WITH_INSTALL_RPATH YES)

0 commit comments

Comments
 (0)