Skip to content

Commit 5b8e349

Browse files
committed
[cmake] Add runpath for libBlocksRuntime.so
Dispatch build leaves artifacts in both the root directory and the src directory, but only the src directory was being added to the runpath, so the libBlocksRuntime.so library might not have been found. Additionally, remove the rpath flags from libdispatch_ldflags, which are used to compile Foundation, but will point to the build directory results. Add those flags instead to a list used for the test binaries. In the end Foundation ends up with a path of `$ORIGIN`; TestFoundation has paths to Foundation, to Dispatch and BlocksRuntime, and to XCTest; while xdgTestHelper points to Foundation, and Dispatch and BlocksRuntime. Extract a small function for adding rpaths to a list, to make the rpath easier to read. Also, remove Android from the rpath flags, since Android will not work with the build tree rpaths, and will need its own solution. For the time being, do not set any rpath.
1 parent 7b72fbd commit 5b8e349

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

CMakeLists.txt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,26 @@ set(libdispatch_ldflags)
9292
if(FOUNDATION_ENABLE_LIBDISPATCH)
9393
set(libdispatch_cflags -I;${FOUNDATION_PATH_TO_LIBDISPATCH_SOURCE};-I;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src/swift;-Xcc;-fblocks)
9494
set(libdispatch_ldflags -L;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD};-L;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src;-ldispatch;-lswiftDispatch)
95-
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL Android OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
96-
list(APPEND libdispatch_ldflags -Xlinker;-rpath;-Xlinker;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src)
97-
endif()
9895
endif()
9996

100-
set(plutil_rpath)
101-
if(CMAKE_SYSTEM_NAME STREQUAL Android OR CMAKE_SYSTEM_NAME STREQUAL Linux OR
102-
CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
103-
set(Foundation_RPATH -Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN")
104-
set(XDG_TEST_HELPER_RPATH -Xlinker;-rpath;-Xlinker;${CMAKE_CURRENT_BINARY_DIR})
105-
set(plutil_rpath -Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN/../lib/swift/${swift_os}")
97+
98+
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
99+
append_linker_rpath(Foundation_RPATH "\\\$\$ORIGIN")
100+
append_linker_rpath(TestFoundation_RPATH ${CMAKE_CURRENT_BINARY_DIR})
101+
append_linker_rpath(TestFoundation_RPATH ${FOUNDATION_PATH_TO_XCTEST_BUILD})
102+
append_linker_rpath(XDG_TEST_HELPER_RPATH ${CMAKE_CURRENT_BINARY_DIR})
103+
append_linker_rpath(plutil_rpath "\\\$\$ORIGIN/../lib/swift/${swift_os}")
104+
if (FOUNDATION_ENABLE_LIBDISPATCH)
105+
# NOTE: the following two are for testing LLDB and others, but should be removed
106+
append_linker_rpath(Foundation_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src)
107+
append_linker_rpath(Foundation_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD})
108+
append_linker_rpath(TestFoundation_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src)
109+
append_linker_rpath(TestFoundation_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD})
110+
append_linker_rpath(XDG_TEST_HELPER_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src)
111+
append_linker_rpath(XDG_TEST_HELPER_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD})
112+
endif()
113+
elseif(CMAKE_SYSTEM_NAME STREQUAL Android)
114+
append_linker_rpath(Foundation_RPATH "\\\$\$ORIGIN")
106115
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
107116
# FIXME(SR9138) Silence "locally defined symbol '…' imported in function '…'
108117
set(WORKAROUND_SR9138 -Xlinker;-ignore:4049;-Xlinker;-ignore:4217)
@@ -544,6 +553,7 @@ if(ENABLE_TESTING)
544553
-L${FOUNDATION_PATH_TO_XCTEST_BUILD}
545554
-lXCTest
546555
${WORKAROUND_SR9138}
556+
${TestFoundation_RPATH}
547557
$<$<PLATFORM_ID:Windows>:-lWS2_32>
548558
RESOURCES
549559
${CMAKE_SOURCE_DIR}/TestFoundation/Resources/Info.plist

cmake/modules/SwiftSupport.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,20 @@ function(get_swift_host_arch result_var_name)
274274
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}")
275275
endif()
276276
endfunction()
277+
278+
279+
# Appends an the given path as an rpath prefixed by the -Xlinker arguments for
280+
# the Swift compiler to pass to the linker.
281+
#
282+
# Usage:
283+
# append_linker_rpath(MyTarget_RPATH one)
284+
# append_linker_rpath(MyTarget_RPATH two)
285+
# # MyTarget_RPATH=-Xlinker;-rpath;-Xlinker;one;-Xlinker;-rpath;-Xlinker;two
286+
#
287+
function(append_linker_rpath result_var_name rpath)
288+
set(tmp ${${result_var_name}})
289+
290+
list(APPEND tmp -Xlinker -rpath -Xlinker "${rpath}")
291+
292+
set(${result_var_name} ${tmp} PARENT_SCOPE)
293+
endfunction()

0 commit comments

Comments
 (0)