From 4919d43aee6779d75479f1f437a4c9fe08764e9f Mon Sep 17 00:00:00 2001 From: YOCKOW Date: Fri, 16 Jul 2021 14:31:57 +0900 Subject: [PATCH 1/4] Add tests for SR-14933. --- .../Tests/TestISO8601DateFormatter.swift | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Tests/Foundation/Tests/TestISO8601DateFormatter.swift b/Tests/Foundation/Tests/TestISO8601DateFormatter.swift index 6054794b7c..e1fdd2d614 100644 --- a/Tests/Foundation/Tests/TestISO8601DateFormatter.swift +++ b/Tests/Foundation/Tests/TestISO8601DateFormatter.swift @@ -326,6 +326,28 @@ class TestISO8601DateFormatter: XCTestCase { try fixture.assertLoadedValuesMatch(areEqual(_:_:)) } } + + func test_copy() throws { + let original = ISO8601DateFormatter() + original.timeZone = try XCTUnwrap(TimeZone(identifier: "GMT")) + original.formatOptions = [ + .withInternetDateTime, + .withDashSeparatorInDate, + .withColonSeparatorInTime, + .withColonSeparatorInTimeZone, + ] + + let copied = try XCTUnwrap(original.copy() as? ISO8601DateFormatter) + XCTAssertEqual(copied.timeZone, original.timeZone) + XCTAssertEqual(copied.formatOptions, original.formatOptions) + + copied.timeZone = try XCTUnwrap(TimeZone(identifier: "JST")) + copied.formatOptions.insert(.withFractionalSeconds) + XCTAssertNotEqual(copied.timeZone, original.timeZone) + XCTAssertNotEqual(copied.formatOptions, original.formatOptions) + XCTAssertFalse(original.formatOptions.contains(.withFractionalSeconds)) + XCTAssertTrue(copied.formatOptions.contains(.withFractionalSeconds)) + } static var allTests : [(String, (TestISO8601DateFormatter) -> () throws -> Void)] { @@ -335,6 +357,7 @@ class TestISO8601DateFormatter: XCTestCase { ("test_stringFromDateClass", test_stringFromDateClass), ("test_codingRoundtrip", test_codingRoundtrip), ("test_loadingFixtures", test_loadingFixtures), + ("test_copy", test_copy), ] } } From f34a2f389fd86e701e3a886b679ee75bb5ff0b3c Mon Sep 17 00:00:00 2001 From: YOCKOW Date: Fri, 16 Jul 2021 14:53:29 +0900 Subject: [PATCH 2/4] Implement `copy()` in `ISO8601DateFormatter`. --- Sources/Foundation/ISO8601DateFormatter.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sources/Foundation/ISO8601DateFormatter.swift b/Sources/Foundation/ISO8601DateFormatter.swift index 0764ca89fd..54de843b52 100644 --- a/Sources/Foundation/ISO8601DateFormatter.swift +++ b/Sources/Foundation/ISO8601DateFormatter.swift @@ -112,6 +112,13 @@ open class ISO8601DateFormatter : Formatter, NSSecureCoding { aCoder.encode(timeZone._nsObject, forKey: "NS.timeZone") } } + + open override func copy(with zone: NSZone? = nil) -> Any { + let copied = ISO8601DateFormatter() + copied.timeZone = timeZone + copied.formatOptions = formatOptions + return copied + } public static var supportsSecureCoding: Bool { return true } From dd02e6627399c508f23d00f0b67c1ff8399d89c6 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 17 Aug 2021 14:05:22 +0000 Subject: [PATCH 3/4] Revert "Revert "Fix autolink mechanism for static libraries on Linux"" This reverts commit 6a6d36c6ac22ef8f1153b94713b1c197929b267f. --- Sources/Foundation/CMakeLists.txt | 12 ++++++++++++ Sources/FoundationNetworking/CMakeLists.txt | 11 +++++++++++ Sources/FoundationXML/CMakeLists.txt | 11 +++++++++++ 3 files changed, 34 insertions(+) diff --git a/Sources/Foundation/CMakeLists.txt b/Sources/Foundation/CMakeLists.txt index 016bf2946f..38b47f0947 100644 --- a/Sources/Foundation/CMakeLists.txt +++ b/Sources/Foundation/CMakeLists.txt @@ -160,6 +160,18 @@ set_target_properties(Foundation PROPERTIES Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift) +if(NOT BUILD_SHARED_LIBS) + 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 + $ + $) +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..c1462d1dc0 100644 --- a/Sources/FoundationNetworking/CMakeLists.txt +++ b/Sources/FoundationNetworking/CMakeLists.txt @@ -64,6 +64,17 @@ target_link_libraries(FoundationNetworking CFURLSessionInterface PUBLIC Foundation) + +if(NOT BUILD_SHARED_LIBS) + 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 + $) +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..913c8f42b3 100644 --- a/Sources/FoundationXML/CMakeLists.txt +++ b/Sources/FoundationXML/CMakeLists.txt @@ -16,6 +16,17 @@ target_link_libraries(FoundationXML CFXMLInterface PUBLIC Foundation) + +if(NOT BUILD_SHARED_LIBS) + 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 + $) +endif() + set_target_properties(FoundationXML PROPERTIES INSTALL_RPATH "$ORIGIN" Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift From f1a5aa7b5c641052460b268467f230b9b3e0841f Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 17 Aug 2021 17:30:18 +0000 Subject: [PATCH 4/4] Determine actual icui18n library name based on CMake package system This patch allows the "swift" suffixed ICU library files --- CMakeLists.txt | 2 ++ CoreFoundation/CMakeLists.txt | 1 - Sources/Foundation/CMakeLists.txt | 14 +++++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a1da877f67..51826131e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,8 @@ if(HAS_LIBDISPATCH_API) find_package(dispatch CONFIG REQUIRED) endif() +find_package(ICU COMPONENTS uc i18n REQUIRED) + include(SwiftSupport) include(GNUInstallDirs) include(XCTest) diff --git a/CoreFoundation/CMakeLists.txt b/CoreFoundation/CMakeLists.txt index 103b5d8a6b..1c06a79668 100644 --- a/CoreFoundation/CMakeLists.txt +++ b/CoreFoundation/CMakeLists.txt @@ -32,7 +32,6 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) else() find_package(CURL REQUIRED) endif() - find_package(ICU COMPONENTS uc i18n REQUIRED) endif() include(GNUInstallDirs) diff --git a/Sources/Foundation/CMakeLists.txt b/Sources/Foundation/CMakeLists.txt index 38b47f0947..f7a4458ba8 100644 --- a/Sources/Foundation/CMakeLists.txt +++ b/Sources/Foundation/CMakeLists.txt @@ -161,10 +161,22 @@ set_target_properties(Foundation PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift) if(NOT BUILD_SHARED_LIBS) + # ICU_I18N_LIBRARY is set by find_package(ICU) in the top level CMakeLists.txt + # It's an absolute path to the found library file + get_target_property(icui18n_path ICU::i18n IMPORTED_LOCATION) + get_filename_component(icu_i18n_basename "${icui18n_path}" NAME_WE) + get_filename_component(icu_i18n_dir "${icui18n_path}" DIRECTORY) + string(REPLACE "lib" "" icu_i18n_basename "${icu_i18n_basename}") + target_compile_options(Foundation PRIVATE - "SHELL:-Xfrontend -public-autolink-library -Xfrontend icui18n + "SHELL:-Xfrontend -public-autolink-library -Xfrontend ${icu_i18n_basename} -Xfrontend -public-autolink-library -Xfrontend BlocksRuntime") + # ICU libraries are linked by absolute library path in this project, + # but -public-autolink-library forces to resolve library path by + # library search path given by -L, so add a directory of icui18n + # in the search path + target_link_directories(Foundation PUBLIC "${icu_i18n_dir}") # Merge private dependencies into single static objects archive set_property(TARGET Foundation PROPERTY STATIC_LIBRARY_OPTIONS