Skip to content

Commit 16f5cef

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 7c9fb6a commit 16f5cef

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

CMakeLists.txt

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,27 @@ 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-
file(TO_CMAKE_PATH "${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}" FOUNDATION_PATH_TO_LIBDISPATCH_BUILD)
97-
list(APPEND libdispatch_ldflags -Xlinker;-rpath;-Xlinker;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src)
98-
endif()
9995
endif()
10096

101-
set(plutil_rpath)
102-
if(CMAKE_SYSTEM_NAME STREQUAL Android OR CMAKE_SYSTEM_NAME STREQUAL Linux OR
103-
CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
104-
set(Foundation_RPATH -Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN")
105-
set(XDG_TEST_HELPER_RPATH -Xlinker;-rpath;-Xlinker;${CMAKE_CURRENT_BINARY_DIR})
106-
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+
file(TO_CMAKE_PATH "${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}" FOUNDATION_PATH_TO_LIBDISPATCH_BUILD)
106+
# NOTE: the following two are for testing LLDB and others, but should be removed
107+
append_linker_rpath(Foundation_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src)
108+
append_linker_rpath(Foundation_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD})
109+
append_linker_rpath(TestFoundation_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src)
110+
append_linker_rpath(TestFoundation_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD})
111+
append_linker_rpath(XDG_TEST_HELPER_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src)
112+
append_linker_rpath(XDG_TEST_HELPER_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD})
113+
endif()
114+
elseif(CMAKE_SYSTEM_NAME STREQUAL Android)
115+
append_linker_rpath(Foundation_RPATH "\\\$\$ORIGIN")
107116
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
108117
# FIXME(SR9138) Silence "locally defined symbol '…' imported in function '…'
109118
set(WORKAROUND_SR9138 -Xlinker;-ignore:4049;-Xlinker;-ignore:4217)
@@ -535,6 +544,7 @@ if(ENABLE_TESTING)
535544
-L${FOUNDATION_PATH_TO_XCTEST_BUILD}
536545
-lXCTest
537546
${WORKAROUND_SR9138}
547+
${TestFoundation_RPATH}
538548
RESOURCES
539549
${CMAKE_SOURCE_DIR}/TestFoundation/Resources/Info.plist
540550
${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSURLTestData.plist

cmake/modules/SwiftSupport.cmake

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

0 commit comments

Comments
 (0)