Skip to content

[cmake] Add runpath for libBlocksRuntime.so #2246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,27 @@ set(libdispatch_ldflags)
if(FOUNDATION_ENABLE_LIBDISPATCH)
set(libdispatch_cflags -I;${FOUNDATION_PATH_TO_LIBDISPATCH_SOURCE};-I;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src/swift;-Xcc;-fblocks)
set(libdispatch_ldflags -L;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD};-L;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src;-ldispatch;-lswiftDispatch)
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL Android OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
file(TO_CMAKE_PATH "${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}" FOUNDATION_PATH_TO_LIBDISPATCH_BUILD)
list(APPEND libdispatch_ldflags -Xlinker;-rpath;-Xlinker;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src)
endif()
endif()

set(plutil_rpath)
if(CMAKE_SYSTEM_NAME STREQUAL Android OR CMAKE_SYSTEM_NAME STREQUAL Linux OR
CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
set(Foundation_RPATH -Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN")
set(XDG_TEST_HELPER_RPATH -Xlinker;-rpath;-Xlinker;${CMAKE_CURRENT_BINARY_DIR})
set(plutil_rpath -Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN/../lib/swift/${swift_os}")

if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
append_linker_rpath(Foundation_RPATH "\\\$\$ORIGIN")
append_linker_rpath(TestFoundation_RPATH ${CMAKE_CURRENT_BINARY_DIR})
append_linker_rpath(TestFoundation_RPATH ${FOUNDATION_PATH_TO_XCTEST_BUILD})
append_linker_rpath(XDG_TEST_HELPER_RPATH ${CMAKE_CURRENT_BINARY_DIR})
append_linker_rpath(plutil_rpath "\\\$\$ORIGIN/../lib/swift/${swift_os}")
if (FOUNDATION_ENABLE_LIBDISPATCH)
file(TO_CMAKE_PATH "${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}" FOUNDATION_PATH_TO_LIBDISPATCH_BUILD)
# NOTE: the following two are for testing LLDB and others, but should be removed
append_linker_rpath(Foundation_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src)
append_linker_rpath(Foundation_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be adding build paths to libFoundation.so we should fix lldb instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That NOTE is the result of our conversation on May 31st: #2246 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spevans: Some decision around this? I can try to fix it in LLDB, but I would l love to not have to modify it in there before merging this. Thanks!

append_linker_rpath(TestFoundation_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src)
append_linker_rpath(TestFoundation_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD})
append_linker_rpath(XDG_TEST_HELPER_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src)
append_linker_rpath(XDG_TEST_HELPER_RPATH ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD})
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL Android)
append_linker_rpath(Foundation_RPATH "\\\$\$ORIGIN")
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
# FIXME(SR9138) Silence "locally defined symbol '…' imported in function '…'
set(WORKAROUND_SR9138 -Xlinker;-ignore:4049;-Xlinker;-ignore:4217)
Expand Down Expand Up @@ -535,6 +544,7 @@ if(ENABLE_TESTING)
-L${FOUNDATION_PATH_TO_XCTEST_BUILD}
-lXCTest
${WORKAROUND_SR9138}
${TestFoundation_RPATH}
RESOURCES
${CMAKE_SOURCE_DIR}/TestFoundation/Resources/Info.plist
${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSURLTestData.plist
Expand Down
17 changes: 17 additions & 0 deletions cmake/modules/SwiftSupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,20 @@ function(get_swift_host_arch result_var_name)
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
endfunction()


# Appends an the given path as an rpath prefixed by the -Xlinker arguments for
# the Swift compiler to pass to the linker.
#
# Usage:
# append_linker_rpath(MyTarget_RPATH one)
# append_linker_rpath(MyTarget_RPATH two)
# # MyTarget_RPATH=-Xlinker;-rpath;-Xlinker;one;-Xlinker;-rpath;-Xlinker;two
#
function(append_linker_rpath result_var_name rpath)
set(tmp ${${result_var_name}})

list(APPEND tmp -Xlinker -rpath -Xlinker "${rpath}")

set(${result_var_name} ${tmp} PARENT_SCOPE)
endfunction()