From f409d1fd76fb5298822546cdda806a7a33ef1581 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 27 Apr 2021 14:24:00 +0000 Subject: [PATCH 1/2] Merge private dependencies into single static library `Foundation` imports `CoreFoundation` with `@_implementationOnly` as a private dependency, and it doesn't emit `IMPORTED_MODULE` in swiftmodule. Users of Foundation can link `libCoreFoundation.so` automatically when using dynamic linking because it's already linked into `libFoundation.so`. However, this automatic linking doesn't work when static linking, so users need to link CoreFoundation and dependent libraries of CoreFoundation explicitly by adding `-lCoreFoundation -lBlocksRuntime -licui18n`. To avoid forcing users to link private dependencies explicitly, this patch changed to merge the dependencies into libFoundation.a. And also to avoid forcing to link dependent libs of CoreFoundation like `curl` or `icui18n`, add `LINK_LIBRARY` entry in Foundation.swiftmodule using `-public-autolink-library` which is introduced by https://github.com/apple/swift/pull/35936 --- Sources/Foundation/CMakeLists.txt | 13 +++++++++++++ Sources/FoundationNetworking/CMakeLists.txt | 13 +++++++++++++ Sources/FoundationXML/CMakeLists.txt | 13 +++++++++++++ 3 files changed, 39 insertions(+) diff --git a/Sources/Foundation/CMakeLists.txt b/Sources/Foundation/CMakeLists.txt index 016bf2946f..495402e44f 100644 --- a/Sources/Foundation/CMakeLists.txt +++ b/Sources/Foundation/CMakeLists.txt @@ -160,6 +160,19 @@ set_target_properties(Foundation PROPERTIES Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift) +if(NOT BUILD_SHARED_LIBS) + # TODO(katei): Comment out after swift-frontend implementation + # https://github.com/apple/swift/pull/35936 + # target_compile_options(Foundation + # PRIVATE + # "SHELL:-public-autolink-library icui18n") + + # Merge private dependencies into single static objects archive + set_property(TARGET Foundation PROPERTY STATIC_LIBRARY_OPTIONS + $ + $) +endif() + if(CMAKE_SYSTEM_NAME STREQUAL Windows) # NOTE: workaround for CMake which doesn't link in OBJECT libraries properly add_dependencies(Foundation CoreFoundationResources) diff --git a/Sources/FoundationNetworking/CMakeLists.txt b/Sources/FoundationNetworking/CMakeLists.txt index 164ef63b91..0abbcdca5f 100644 --- a/Sources/FoundationNetworking/CMakeLists.txt +++ b/Sources/FoundationNetworking/CMakeLists.txt @@ -64,6 +64,19 @@ target_link_libraries(FoundationNetworking CFURLSessionInterface PUBLIC Foundation) + +if(NOT BUILD_SHARED_LIBS) + # TODO(katei): Comment out after swift-frontend implementation + # https://github.com/apple/swift/pull/35936 + # target_compile_options(FoundationNetworking + # PRIVATE + # "SHELL:-public-autolink-library curl") + + # Merge private dependencies into single static objects archive + set_property(TARGET FoundationNetworking PROPERTY STATIC_LIBRARY_OPTIONS + $) +endif() + set_target_properties(FoundationNetworking PROPERTIES INSTALL_RPATH "$ORIGIN" Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift diff --git a/Sources/FoundationXML/CMakeLists.txt b/Sources/FoundationXML/CMakeLists.txt index cbc1a95ba3..6ffc0a6387 100644 --- a/Sources/FoundationXML/CMakeLists.txt +++ b/Sources/FoundationXML/CMakeLists.txt @@ -16,6 +16,19 @@ target_link_libraries(FoundationXML CFXMLInterface PUBLIC Foundation) + +if(NOT BUILD_SHARED_LIBS) + # TODO(katei): Comment out after swift-frontend implementation + # https://github.com/apple/swift/pull/35936 + # target_compile_options(FoundationXML + # PRIVATE + # "SHELL:-public-autolink-library xml2") + + # Merge private dependencies into single static objects archive + set_property(TARGET FoundationXML PROPERTY STATIC_LIBRARY_OPTIONS + $) +endif() + set_target_properties(FoundationXML PROPERTIES INSTALL_RPATH "$ORIGIN" Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift From 718159e7108cc29fcba8b5477a59b1f766992d4f Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 27 Apr 2021 16:41:51 +0000 Subject: [PATCH 2/2] Add public dependent libraries using -public-autolink-library --- Sources/Foundation/CMakeLists.txt | 9 ++++----- Sources/FoundationNetworking/CMakeLists.txt | 8 +++----- Sources/FoundationXML/CMakeLists.txt | 8 +++----- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Sources/Foundation/CMakeLists.txt b/Sources/Foundation/CMakeLists.txt index 495402e44f..38b47f0947 100644 --- a/Sources/Foundation/CMakeLists.txt +++ b/Sources/Foundation/CMakeLists.txt @@ -161,11 +161,10 @@ set_target_properties(Foundation PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift) if(NOT BUILD_SHARED_LIBS) - # TODO(katei): Comment out after swift-frontend implementation - # https://github.com/apple/swift/pull/35936 - # target_compile_options(Foundation - # PRIVATE - # "SHELL:-public-autolink-library icui18n") + target_compile_options(Foundation + PRIVATE + "SHELL:-Xfrontend -public-autolink-library -Xfrontend icui18n + -Xfrontend -public-autolink-library -Xfrontend BlocksRuntime") # Merge private dependencies into single static objects archive set_property(TARGET Foundation PROPERTY STATIC_LIBRARY_OPTIONS diff --git a/Sources/FoundationNetworking/CMakeLists.txt b/Sources/FoundationNetworking/CMakeLists.txt index 0abbcdca5f..c1462d1dc0 100644 --- a/Sources/FoundationNetworking/CMakeLists.txt +++ b/Sources/FoundationNetworking/CMakeLists.txt @@ -66,11 +66,9 @@ target_link_libraries(FoundationNetworking Foundation) if(NOT BUILD_SHARED_LIBS) - # TODO(katei): Comment out after swift-frontend implementation - # https://github.com/apple/swift/pull/35936 - # target_compile_options(FoundationNetworking - # PRIVATE - # "SHELL:-public-autolink-library curl") + target_compile_options(FoundationNetworking + PRIVATE + "SHELL:-Xfrontend -public-autolink-library -Xfrontend curl") # Merge private dependencies into single static objects archive set_property(TARGET FoundationNetworking PROPERTY STATIC_LIBRARY_OPTIONS diff --git a/Sources/FoundationXML/CMakeLists.txt b/Sources/FoundationXML/CMakeLists.txt index 6ffc0a6387..913c8f42b3 100644 --- a/Sources/FoundationXML/CMakeLists.txt +++ b/Sources/FoundationXML/CMakeLists.txt @@ -18,11 +18,9 @@ target_link_libraries(FoundationXML Foundation) if(NOT BUILD_SHARED_LIBS) - # TODO(katei): Comment out after swift-frontend implementation - # https://github.com/apple/swift/pull/35936 - # target_compile_options(FoundationXML - # PRIVATE - # "SHELL:-public-autolink-library xml2") + target_compile_options(FoundationXML + PRIVATE + "SHELL:-Xfrontend -public-autolink-library -Xfrontend xml2") # Merge private dependencies into single static objects archive set_property(TARGET FoundationXML PROPERTY STATIC_LIBRARY_OPTIONS