From e13169dab8b339b91cb7d22571626d4e8675047c Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Mon, 18 Nov 2024 16:34:52 -0800 Subject: [PATCH 1/2] [cmake] Set up rpath for macOS binaries * Make `SourceControl` a shared library. The library is shared across multiple other libraries (`Commands`, `PackageGraph` and `PackageLoading`), resulting in duplicate definitions in shared libraries. * Set rpath for macOS binaries, resulting in binaries ready to be used post-installation. --- Sources/SourceControl/CMakeLists.txt | 8 +++++++- Sources/swift-build/CMakeLists.txt | 3 +++ Sources/swift-experimental-sdk/CMakeLists.txt | 3 +++ Sources/swift-package/CMakeLists.txt | 3 +++ Sources/swift-run/CMakeLists.txt | 3 +++ Sources/swift-sdk/CMakeLists.txt | 3 +++ Sources/swift-test/CMakeLists.txt | 3 +++ 7 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Sources/SourceControl/CMakeLists.txt b/Sources/SourceControl/CMakeLists.txt index 56a9c2a917a..8e1377d9b1b 100644 --- a/Sources/SourceControl/CMakeLists.txt +++ b/Sources/SourceControl/CMakeLists.txt @@ -6,7 +6,7 @@ # See http://swift.org/LICENSE.txt for license information # See http://swift.org/CONTRIBUTORS.txt for Swift project authors -add_library(SourceControl STATIC +add_library(SourceControl GitRepository.swift Repository.swift RepositoryManager.swift) @@ -20,3 +20,9 @@ target_link_libraries(SourceControl PUBLIC # NOTE(compnerd) workaround for CMake not setting up include flags yet set_target_properties(SourceControl PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +install(TARGETS SourceControl + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin) +set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS SourceControl) diff --git a/Sources/swift-build/CMakeLists.txt b/Sources/swift-build/CMakeLists.txt index 936298a6fad..1ab67260755 100644 --- a/Sources/swift-build/CMakeLists.txt +++ b/Sources/swift-build/CMakeLists.txt @@ -14,5 +14,8 @@ target_link_libraries(swift-build PRIVATE target_compile_options(swift-build PRIVATE -parse-as-library) +set_target_properties(swift-build PROPERTIES + INSTALL_RPATH "$<$:@executable_path/../lib;@executable_path/../lib/swift/macosx;@executable_path/../lib/swift/host;@executable_path/../lib/swift/pm/llbuild>") + install(TARGETS swift-build DESTINATION bin) diff --git a/Sources/swift-experimental-sdk/CMakeLists.txt b/Sources/swift-experimental-sdk/CMakeLists.txt index edad12be83b..5b8c58dc302 100644 --- a/Sources/swift-experimental-sdk/CMakeLists.txt +++ b/Sources/swift-experimental-sdk/CMakeLists.txt @@ -14,5 +14,8 @@ target_link_libraries(swift-experimental-sdk PRIVATE target_compile_options(swift-experimental-sdk PRIVATE -parse-as-library) +set_target_properties(swift-experimental-sdk PROPERTIES + INSTALL_RPATH "$<$:@executable_path/../lib;@executable_path/../lib/swift/macosx;@executable_path/../lib/swift/host;@executable_path/../lib/swift/pm/llbuild>") + install(TARGETS swift-experimental-sdk RUNTIME DESTINATION bin) diff --git a/Sources/swift-package/CMakeLists.txt b/Sources/swift-package/CMakeLists.txt index 3468bdefcdc..a7e327f2b3b 100644 --- a/Sources/swift-package/CMakeLists.txt +++ b/Sources/swift-package/CMakeLists.txt @@ -15,5 +15,8 @@ target_link_libraries(swift-package PRIVATE target_compile_options(swift-package PRIVATE -parse-as-library) +set_target_properties(swift-package PROPERTIES + INSTALL_RPATH "$<$:@executable_path/../lib;@executable_path/../lib/swift/macosx;@executable_path/../lib/swift/host;@executable_path/../lib/swift/pm/llbuild>") + install(TARGETS swift-package RUNTIME DESTINATION bin) diff --git a/Sources/swift-run/CMakeLists.txt b/Sources/swift-run/CMakeLists.txt index 9c609f84ea1..a61e1990356 100644 --- a/Sources/swift-run/CMakeLists.txt +++ b/Sources/swift-run/CMakeLists.txt @@ -14,5 +14,8 @@ target_link_libraries(swift-run PRIVATE target_compile_options(swift-run PRIVATE -parse-as-library) +set_target_properties(swift-run PROPERTIES + INSTALL_RPATH "$<$:@executable_path/../lib;@executable_path/../lib/swift/macosx;@executable_path/../lib/swift/host;@executable_path/../lib/swift/pm/llbuild>") + install(TARGETS swift-run RUNTIME DESTINATION bin) diff --git a/Sources/swift-sdk/CMakeLists.txt b/Sources/swift-sdk/CMakeLists.txt index ee3be128bae..fabfc9d9b19 100644 --- a/Sources/swift-sdk/CMakeLists.txt +++ b/Sources/swift-sdk/CMakeLists.txt @@ -14,5 +14,8 @@ target_link_libraries(swift-sdk PRIVATE target_compile_options(swift-sdk PRIVATE -parse-as-library) +set_target_properties(swift-sdk PROPERTIES + INSTALL_RPATH "$<$:@executable_path/../lib;@executable_path/../lib/swift/macosx;@executable_path/../lib/swift/host;@executable_path/../lib/swift/pm/llbuild>") + install(TARGETS swift-sdk RUNTIME DESTINATION bin) diff --git a/Sources/swift-test/CMakeLists.txt b/Sources/swift-test/CMakeLists.txt index 79c910294fd..76f965d6ca7 100644 --- a/Sources/swift-test/CMakeLists.txt +++ b/Sources/swift-test/CMakeLists.txt @@ -14,5 +14,8 @@ target_link_libraries(swift-test PRIVATE target_compile_options(swift-test PRIVATE -parse-as-library) +set_target_properties(swift-test PROPERTIES + INSTALL_RPATH "$<$:@executable_path/../lib;@executable_path/../lib/swift/macosx;@executable_path/../lib/swift/host;@executable_path/../lib/swift/pm/llbuild>") + install(TARGETS swift-test RUNTIME DESTINATION bin) From af4087c448211cea9c282e577560eb4217cc5f2d Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Wed, 20 Nov 2024 11:28:13 -0800 Subject: [PATCH 2/2] Remove rpath modifications --- Sources/swift-build/CMakeLists.txt | 3 --- Sources/swift-experimental-sdk/CMakeLists.txt | 3 --- Sources/swift-package/CMakeLists.txt | 3 --- Sources/swift-run/CMakeLists.txt | 3 --- Sources/swift-sdk/CMakeLists.txt | 3 --- Sources/swift-test/CMakeLists.txt | 3 --- 6 files changed, 18 deletions(-) diff --git a/Sources/swift-build/CMakeLists.txt b/Sources/swift-build/CMakeLists.txt index 1ab67260755..936298a6fad 100644 --- a/Sources/swift-build/CMakeLists.txt +++ b/Sources/swift-build/CMakeLists.txt @@ -14,8 +14,5 @@ target_link_libraries(swift-build PRIVATE target_compile_options(swift-build PRIVATE -parse-as-library) -set_target_properties(swift-build PROPERTIES - INSTALL_RPATH "$<$:@executable_path/../lib;@executable_path/../lib/swift/macosx;@executable_path/../lib/swift/host;@executable_path/../lib/swift/pm/llbuild>") - install(TARGETS swift-build DESTINATION bin) diff --git a/Sources/swift-experimental-sdk/CMakeLists.txt b/Sources/swift-experimental-sdk/CMakeLists.txt index 5b8c58dc302..edad12be83b 100644 --- a/Sources/swift-experimental-sdk/CMakeLists.txt +++ b/Sources/swift-experimental-sdk/CMakeLists.txt @@ -14,8 +14,5 @@ target_link_libraries(swift-experimental-sdk PRIVATE target_compile_options(swift-experimental-sdk PRIVATE -parse-as-library) -set_target_properties(swift-experimental-sdk PROPERTIES - INSTALL_RPATH "$<$:@executable_path/../lib;@executable_path/../lib/swift/macosx;@executable_path/../lib/swift/host;@executable_path/../lib/swift/pm/llbuild>") - install(TARGETS swift-experimental-sdk RUNTIME DESTINATION bin) diff --git a/Sources/swift-package/CMakeLists.txt b/Sources/swift-package/CMakeLists.txt index a7e327f2b3b..3468bdefcdc 100644 --- a/Sources/swift-package/CMakeLists.txt +++ b/Sources/swift-package/CMakeLists.txt @@ -15,8 +15,5 @@ target_link_libraries(swift-package PRIVATE target_compile_options(swift-package PRIVATE -parse-as-library) -set_target_properties(swift-package PROPERTIES - INSTALL_RPATH "$<$:@executable_path/../lib;@executable_path/../lib/swift/macosx;@executable_path/../lib/swift/host;@executable_path/../lib/swift/pm/llbuild>") - install(TARGETS swift-package RUNTIME DESTINATION bin) diff --git a/Sources/swift-run/CMakeLists.txt b/Sources/swift-run/CMakeLists.txt index a61e1990356..9c609f84ea1 100644 --- a/Sources/swift-run/CMakeLists.txt +++ b/Sources/swift-run/CMakeLists.txt @@ -14,8 +14,5 @@ target_link_libraries(swift-run PRIVATE target_compile_options(swift-run PRIVATE -parse-as-library) -set_target_properties(swift-run PROPERTIES - INSTALL_RPATH "$<$:@executable_path/../lib;@executable_path/../lib/swift/macosx;@executable_path/../lib/swift/host;@executable_path/../lib/swift/pm/llbuild>") - install(TARGETS swift-run RUNTIME DESTINATION bin) diff --git a/Sources/swift-sdk/CMakeLists.txt b/Sources/swift-sdk/CMakeLists.txt index fabfc9d9b19..ee3be128bae 100644 --- a/Sources/swift-sdk/CMakeLists.txt +++ b/Sources/swift-sdk/CMakeLists.txt @@ -14,8 +14,5 @@ target_link_libraries(swift-sdk PRIVATE target_compile_options(swift-sdk PRIVATE -parse-as-library) -set_target_properties(swift-sdk PROPERTIES - INSTALL_RPATH "$<$:@executable_path/../lib;@executable_path/../lib/swift/macosx;@executable_path/../lib/swift/host;@executable_path/../lib/swift/pm/llbuild>") - install(TARGETS swift-sdk RUNTIME DESTINATION bin) diff --git a/Sources/swift-test/CMakeLists.txt b/Sources/swift-test/CMakeLists.txt index 76f965d6ca7..79c910294fd 100644 --- a/Sources/swift-test/CMakeLists.txt +++ b/Sources/swift-test/CMakeLists.txt @@ -14,8 +14,5 @@ target_link_libraries(swift-test PRIVATE target_compile_options(swift-test PRIVATE -parse-as-library) -set_target_properties(swift-test PROPERTIES - INSTALL_RPATH "$<$:@executable_path/../lib;@executable_path/../lib/swift/macosx;@executable_path/../lib/swift/host;@executable_path/../lib/swift/pm/llbuild>") - install(TARGETS swift-test RUNTIME DESTINATION bin)