Skip to content

Commit fbf1bc3

Browse files
authored
Merge pull request #339 from swiftwasm/main
[pull] swiftwasm from main
2 parents 6856f76 + 075707c commit fbf1bc3

File tree

7 files changed

+68
-5
lines changed

7 files changed

+68
-5
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ if(HAS_LIBDISPATCH_API)
4747
find_package(dispatch CONFIG REQUIRED)
4848
endif()
4949

50+
find_package(ICU COMPONENTS uc i18n REQUIRED)
51+
5052
include(SwiftSupport)
5153
include(GNUInstallDirs)
5254
include(XCTest)

CoreFoundation/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
3838
find_package(CURL REQUIRED)
3939
endif()
4040
endif()
41-
find_package(ICU COMPONENTS uc i18n REQUIRED)
4241
endif()
4342

4443
include(GNUInstallDirs)

Sources/Foundation/CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,27 @@ set_target_properties(Foundation PROPERTIES
166166
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift)
167167

168168
if(NOT BUILD_SHARED_LIBS)
169-
add_dependencies(Foundation CoreFoundation uuid)
169+
# ICU_I18N_LIBRARY is set by find_package(ICU) in the top level CMakeLists.txt
170+
# It's an absolute path to the found library file
171+
get_target_property(icui18n_path ICU::i18n IMPORTED_LOCATION)
172+
get_filename_component(icu_i18n_basename "${icui18n_path}" NAME_WE)
173+
get_filename_component(icu_i18n_dir "${icui18n_path}" DIRECTORY)
174+
string(REPLACE "lib" "" icu_i18n_basename "${icu_i18n_basename}")
175+
170176
target_compile_options(Foundation
171177
PRIVATE
172-
"SHELL:-Xfrontend -public-autolink-library -Xfrontend icui18n
178+
"SHELL:-Xfrontend -public-autolink-library -Xfrontend ${icu_i18n_basename}
173179
-Xfrontend -public-autolink-library -Xfrontend BlocksRuntime")
180+
# ICU libraries are linked by absolute library path in this project,
181+
# but -public-autolink-library forces to resolve library path by
182+
# library search path given by -L, so add a directory of icui18n
183+
# in the search path
184+
target_link_directories(Foundation PUBLIC "${icu_i18n_dir}")
174185

175186
# Merge private dependencies into single static objects archive
176187
set_property(TARGET Foundation PROPERTY STATIC_LIBRARY_OPTIONS
177188
$<TARGET_OBJECTS:CoreFoundation>
178-
$<TARGET_OBJECTS:uuid>
179-
$<TARGET_OBJECTS:BlocksRuntime>)
189+
$<TARGET_OBJECTS:uuid>)
180190
endif()
181191

182192
if(CMAKE_SYSTEM_NAME STREQUAL Windows)

Sources/Foundation/ISO8601DateFormatter.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ open class ISO8601DateFormatter : Formatter, NSSecureCoding {
112112
aCoder.encode(timeZone._nsObject, forKey: "NS.timeZone")
113113
}
114114
}
115+
116+
open override func copy(with zone: NSZone? = nil) -> Any {
117+
let copied = ISO8601DateFormatter()
118+
copied.timeZone = timeZone
119+
copied.formatOptions = formatOptions
120+
return copied
121+
}
115122

116123
public static var supportsSecureCoding: Bool { return true }
117124

Sources/FoundationNetworking/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ target_link_libraries(FoundationNetworking
6464
CFURLSessionInterface
6565
PUBLIC
6666
Foundation)
67+
68+
if(NOT BUILD_SHARED_LIBS)
69+
target_compile_options(FoundationNetworking
70+
PRIVATE
71+
"SHELL:-Xfrontend -public-autolink-library -Xfrontend curl")
72+
73+
# Merge private dependencies into single static objects archive
74+
set_property(TARGET FoundationNetworking PROPERTY STATIC_LIBRARY_OPTIONS
75+
$<TARGET_OBJECTS:CFURLSessionInterface>)
76+
endif()
77+
6778
set_target_properties(FoundationNetworking PROPERTIES
6879
INSTALL_RPATH "$ORIGIN"
6980
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift

Sources/FoundationXML/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ target_link_libraries(FoundationXML
1616
CFXMLInterface
1717
PUBLIC
1818
Foundation)
19+
20+
if(NOT BUILD_SHARED_LIBS)
21+
target_compile_options(FoundationXML
22+
PRIVATE
23+
"SHELL:-Xfrontend -public-autolink-library -Xfrontend xml2")
24+
25+
# Merge private dependencies into single static objects archive
26+
set_property(TARGET FoundationXML PROPERTY STATIC_LIBRARY_OPTIONS
27+
$<TARGET_OBJECTS:CFXMLInterface>)
28+
endif()
29+
1930
set_target_properties(FoundationXML PROPERTIES
2031
INSTALL_RPATH "$ORIGIN"
2132
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift

Tests/Foundation/Tests/TestISO8601DateFormatter.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,28 @@ class TestISO8601DateFormatter: XCTestCase {
326326
try fixture.assertLoadedValuesMatch(areEqual(_:_:))
327327
}
328328
}
329+
330+
func test_copy() throws {
331+
let original = ISO8601DateFormatter()
332+
original.timeZone = try XCTUnwrap(TimeZone(identifier: "GMT"))
333+
original.formatOptions = [
334+
.withInternetDateTime,
335+
.withDashSeparatorInDate,
336+
.withColonSeparatorInTime,
337+
.withColonSeparatorInTimeZone,
338+
]
339+
340+
let copied = try XCTUnwrap(original.copy() as? ISO8601DateFormatter)
341+
XCTAssertEqual(copied.timeZone, original.timeZone)
342+
XCTAssertEqual(copied.formatOptions, original.formatOptions)
343+
344+
copied.timeZone = try XCTUnwrap(TimeZone(identifier: "JST"))
345+
copied.formatOptions.insert(.withFractionalSeconds)
346+
XCTAssertNotEqual(copied.timeZone, original.timeZone)
347+
XCTAssertNotEqual(copied.formatOptions, original.formatOptions)
348+
XCTAssertFalse(original.formatOptions.contains(.withFractionalSeconds))
349+
XCTAssertTrue(copied.formatOptions.contains(.withFractionalSeconds))
350+
}
329351

330352
static var allTests : [(String, (TestISO8601DateFormatter) -> () throws -> Void)] {
331353

@@ -335,6 +357,7 @@ class TestISO8601DateFormatter: XCTestCase {
335357
("test_stringFromDateClass", test_stringFromDateClass),
336358
("test_codingRoundtrip", test_codingRoundtrip),
337359
("test_loadingFixtures", test_loadingFixtures),
360+
("test_copy", test_copy),
338361
]
339362
}
340363
}

0 commit comments

Comments
 (0)