Skip to content

build: honour and use RPATHs #2559

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

Merged
merged 1 commit into from
Nov 12, 2019
Merged
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
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ enable_testing()
# Cache the variable to allow the user to alter the configuration.
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" CACHE
STRING "MSVC Runtime Library")
if(CMAKE_VERSION VERSION_LESS 3.16.0)
if(NOT (CMAKE_SYSTEM_NAME STREQUAL Windows OR CMAKE_SYSTEM_NAME STREQUAL Darwin))
set(CMAKE_SHARED_LIBRARY_RUNTIME_Swift_FLAG "-Xlinker -rpath -Xlinker ")
set(CMAKE_SHARED_LIBRARY_RUNTIME_Swift_FLAG_SEP ":")
endif()
endif()

option(BUILD_SHARED_LIBS "build shared libraries" ON)

Expand Down
5 changes: 5 additions & 0 deletions Foundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ target_link_libraries(Foundation PRIVATE
uuid)
target_link_libraries(Foundation PUBLIC
swiftDispatch)

# TODO(compnerd) properly propogate `BUILD_RPATH` to the target using CMake
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
target_link_options(Foundation PRIVATE
Expand All @@ -163,6 +164,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
pathcch)
endif()
set_target_properties(Foundation PROPERTIES
INSTALL_RPATH "$ORIGIN"
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift)

Expand Down Expand Up @@ -212,6 +214,7 @@ target_link_libraries(FoundationNetworking PRIVATE
Foundation
CFURLSessionInterface)
set_target_properties(FoundationNetworking PROPERTIES
INSTALL_RPATH "$ORIGIN"
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift)

Expand All @@ -236,9 +239,11 @@ target_link_libraries(FoundationXML PRIVATE
Foundation
CFXMLInterface)
set_target_properties(FoundationXML PROPERTIES
INSTALL_RPATH "$ORIGIN"
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift)


set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS
Foundation FoundationNetworking FoundationXML)
get_swift_host_arch(swift_arch)
Expand Down
7 changes: 2 additions & 5 deletions Tools/plutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ add_executable(plutil
main.swift)
target_link_libraries(plutil PRIVATE
Foundation)
# TODO(compnerd) properly propogate `BUILD_RPATH` to the target using CMake
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
target_link_options(plutil PRIVATE
"SHELL:-Xlinker -rpath -Xlinker $$$$ORIGIN/../lib/swift/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>:$<TARGET_FILE_DIR:Foundation>")
endif()
set_target_properties(plutil PROPERTIES
INSTALL_RPATH "$ORIGIN/../lib/swift/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
Copy link
Member

Choose a reason for hiding this comment

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

Hey @compnerd, I just noticed that this broke the plutil command on linux, because it's not adding this relative rpath for 5.2 or master. I tried various ways to fix it, such as reverting back to

target_link_options(plutil PRIVATE "SHELL:-Xlinker -rpath -Xlinker \\\$\$ORIGIN/../lib/swift/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")

but nothing worked for me, maybe you know how to fix this.

Copy link
Member

Choose a reason for hiding this comment

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

@CodaFi, I don't know how close you guys are to shipping the 5.2 release, but I get the following when running plutil from the latest official 5.2 snapshot build on linux, because of this missing rpath:

> ./swift-5.2-DEVELOPMENT-SNAPSHOT-2020-03-19-a-ubuntu18.04/usr/bin/plutil -help
./swift-5.2-DEVELOPMENT-SNAPSHOT-2020-03-19-a-ubuntu18.04/usr/bin/plutil: error while loading shared libraries: libicuucswift.so.65: cannot open shared object file: No such file or directory
> readelf -d swift-5.2-DEVELOPMENT-SNAPSHOT-2020-03-19-a-ubuntu18.04/usr/bin/plutil  | ag runpath
 0x000000000000001d (RUNPATH)            Library runpath: [/home/buildnode/jenkins/workspace/oss-swift-5.2-package-linux-ubuntu-18_04/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux] 

Prefixing with LD_LIBRARY_PATH gets it working again, so it's clearly the rpath issue. I don't know how much this executable matters, but it's broken.


set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS plutil)
install(TARGETS plutil
Expand Down