-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Package.swift
363 lines (350 loc) · 11.9 KB
/
Package.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let platformsWithThreads: [Platform] = [
.iOS,
.macOS,
.tvOS,
.watchOS,
.macCatalyst,
.driverKit,
.android,
.linux,
.windows,
]
var dispatchIncludeFlags: [CSetting] = []
if let environmentPath = Context.environment["DISPATCH_INCLUDE_PATH"] {
dispatchIncludeFlags.append(.unsafeFlags([
"-I\(environmentPath)",
"-I\(environmentPath)/Block"
]))
} else {
dispatchIncludeFlags.append(
.unsafeFlags([
"-I/usr/lib/swift",
"-I/usr/lib/swift/Block"
], .when(platforms: [.linux]))
)
if let sdkRoot = Context.environment["SDKROOT"] {
dispatchIncludeFlags.append(.unsafeFlags([
"-I\(sdkRoot)usr\\include",
"-I\(sdkRoot)usr\\include\\Block",
], .when(platforms: [.windows])))
}
}
var libxmlIncludeFlags: [CSetting] = []
if let environmentPath = Context.environment["LIBXML_INCLUDE_PATH"] {
libxmlIncludeFlags = [
.unsafeFlags([
"-I\(environmentPath)"
]),
.define("LIBXML_STATIC")
]
}
var curlIncludeFlags: [CSetting] = []
if let environmentPath = Context.environment["CURL_INCLUDE_PATH"] {
curlIncludeFlags = [
.unsafeFlags([
"-I\(environmentPath)"
]),
.define("CURL_STATICLIB")
]
}
var curlLinkFlags: [LinkerSetting] = [
.linkedLibrary("libcurl.lib", .when(platforms: [.windows])),
.linkedLibrary("zlibstatic.lib", .when(platforms: [.windows]))
]
if let environmentPath = Context.environment["CURL_LIBRARY_PATH"] {
curlLinkFlags.append(.unsafeFlags([
"-L\(environmentPath)"
]))
}
if let environmentPath = Context.environment["ZLIB_LIBRARY_PATH"] {
curlLinkFlags.append(.unsafeFlags([
"-L\(environmentPath)"
]))
}
var libxmlLinkFlags: [LinkerSetting] = [
.linkedLibrary("libxml2s.lib", .when(platforms: [.windows]))
]
if let environmentPath = Context.environment["LIBXML_LIBRARY_PATH"] {
libxmlLinkFlags.append(.unsafeFlags([
"-L\(environmentPath)"
]))
}
let coreFoundationBuildSettings: [CSetting] = [
.headerSearchPath("internalInclude"),
.define("DEBUG", .when(configuration: .debug)),
.define("CF_BUILDING_CF"),
.define("CF_WINDOWS_EXECUTABLE_INITIALIZER", .when(platforms: [.windows])), // Ensure __CFInitialize is run even when statically linked into an executable
.define("DEPLOYMENT_ENABLE_LIBDISPATCH", .when(platforms: platformsWithThreads)),
.define("DEPLOYMENT_RUNTIME_SWIFT"),
.define("HAVE_STRUCT_TIMESPEC"),
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS", .when(platforms: platformsWithThreads)),
.define("_GNU_SOURCE", .when(platforms: [.linux, .android])),
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
.unsafeFlags([
"-Wno-shorten-64-to-32",
"-Wno-deprecated-declarations",
"-Wno-unreachable-code",
"-Wno-conditional-uninitialized",
"-Wno-unused-variable",
"-Wno-unused-function",
"-Wno-microsoft-enum-forward-reference",
"-Wno-int-conversion",
"-Wno-switch",
"-fconstant-cfstrings",
"-fexceptions", // TODO: not on OpenBSD
"-fdollars-in-identifiers",
"-fno-common",
"-fcf-runtime-abi=swift",
"-include",
"\(Context.packageDirectory)/Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h",
// /EHsc for Windows
])
] + dispatchIncludeFlags
// For _CFURLSessionInterface, _CFXMLInterface
let interfaceBuildSettings: [CSetting] = [
.headerSearchPath("../CoreFoundation/internalInclude"),
.define("DEBUG", .when(configuration: .debug)),
.define("CF_BUILDING_CF"),
.define("DEPLOYMENT_ENABLE_LIBDISPATCH"),
.define("HAVE_STRUCT_TIMESPEC"),
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS", .when(platforms: platformsWithThreads)),
.define("_GNU_SOURCE", .when(platforms: [.linux, .android])),
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
.unsafeFlags([
"-Wno-shorten-64-to-32",
"-Wno-deprecated-declarations",
"-Wno-unreachable-code",
"-Wno-conditional-uninitialized",
"-Wno-unused-variable",
"-Wno-unused-function",
"-Wno-microsoft-enum-forward-reference",
"-Wno-int-conversion",
"-fconstant-cfstrings",
"-fexceptions", // TODO: not on OpenBSD
"-fdollars-in-identifiers",
"-fno-common",
"-fcf-runtime-abi=swift"
// /EHsc for Windows
])
] + dispatchIncludeFlags
let swiftBuildSettings: [SwiftSetting] = [
.define("DEPLOYMENT_RUNTIME_SWIFT"),
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS"),
.swiftLanguageMode(.v6),
.unsafeFlags([
"-Xfrontend",
"-require-explicit-sendable",
])
]
var dependencies: [Package.Dependency] = []
if let useLocalDepsEnv = Context.environment["SWIFTCI_USE_LOCAL_DEPS"] {
let root: String
if useLocalDepsEnv == "1" {
root = ".."
} else {
root = useLocalDepsEnv
}
dependencies +=
[
.package(
name: "swift-foundation-icu",
path: "\(root)/swift-foundation-icu"),
.package(
name: "swift-foundation",
path: "\(root)/swift-foundation")
]
} else {
dependencies +=
[
.package(
url: "https://github.com/apple/swift-foundation-icu",
branch: "main"),
.package(
url: "https://github.com/apple/swift-foundation",
branch: "main")
]
}
let package = Package(
name: "swift-corelibs-foundation",
// Deployment target note: This package only builds for non-Darwin targets.
platforms: [.macOS("99.9")],
products: [
.library(name: "Foundation", targets: ["Foundation"]),
.library(name: "FoundationXML", targets: ["FoundationXML"]),
.library(name: "FoundationNetworking", targets: ["FoundationNetworking"]),
.executable(name: "plutil", targets: ["plutil"]),
],
dependencies: dependencies,
targets: [
.target(
name: "Foundation",
dependencies: [
.product(name: "FoundationEssentials", package: "swift-foundation"),
.product(name: "FoundationInternationalization", package: "swift-foundation"),
"CoreFoundation"
],
path: "Sources/Foundation",
exclude: [
"CMakeLists.txt"
],
swiftSettings: swiftBuildSettings
),
.target(
name: "FoundationXML",
dependencies: [
.product(name: "FoundationEssentials", package: "swift-foundation"),
"Foundation",
"CoreFoundation",
"_CFXMLInterface",
.target(name: "BlocksRuntime", condition: .when(platforms: [.wasi])),
],
path: "Sources/FoundationXML",
exclude: [
"CMakeLists.txt"
],
swiftSettings: swiftBuildSettings
),
.target(
name: "FoundationNetworking",
dependencies: [
.product(name: "FoundationEssentials", package: "swift-foundation"),
"Foundation",
"CoreFoundation",
"_CFURLSessionInterface"
],
path: "Sources/FoundationNetworking",
exclude: [
"CMakeLists.txt"
],
swiftSettings: swiftBuildSettings
),
.target(
name: "CoreFoundation",
dependencies: [
.product(name: "_FoundationICU", package: "swift-foundation-icu"),
.target(name: "BlocksRuntime", condition: .when(platforms: [.wasi])),
],
path: "Sources/CoreFoundation",
exclude: [
"BlockRuntime",
"CMakeLists.txt"
],
cSettings: coreFoundationBuildSettings,
linkerSettings: [.linkedLibrary("log", .when(platforms: [.android]))]
),
.target(
name: "BlocksRuntime",
path: "Sources/CoreFoundation/BlockRuntime",
exclude: [
"CMakeLists.txt"
],
cSettings: [
// For CFTargetConditionals.h
.headerSearchPath("../include"),
]
),
.target(
name: "_CFXMLInterface",
dependencies: [
"CoreFoundation",
.target(name: "Clibxml2", condition: .when(platforms: [.linux, .android])),
],
path: "Sources/_CFXMLInterface",
exclude: [
"CMakeLists.txt"
],
cSettings: interfaceBuildSettings + libxmlIncludeFlags,
linkerSettings: libxmlLinkFlags
),
.target(
name: "_CFURLSessionInterface",
dependencies: [
"CoreFoundation",
.target(name: "Clibcurl", condition: .when(platforms: [.linux, .android])),
],
path: "Sources/_CFURLSessionInterface",
exclude: [
"CMakeLists.txt"
],
cSettings: interfaceBuildSettings + curlIncludeFlags,
linkerSettings: curlLinkFlags
),
.systemLibrary(
name: "Clibxml2",
pkgConfig: "libxml-2.0",
providers: [
.brew(["libxml2"]),
.apt(["libxml2-dev"])
]
),
.systemLibrary(
name: "Clibcurl",
pkgConfig: "libcurl",
providers: [
.brew(["libcurl"]),
.apt(["libcurl"])
]
),
.executableTarget(
name: "plutil",
dependencies: [
"Foundation"
],
exclude: [
"CMakeLists.txt"
],
swiftSettings: [
.swiftLanguageMode(.v6)
]
),
.executableTarget(
name: "xdgTestHelper",
dependencies: [
"Foundation",
"FoundationXML",
"FoundationNetworking"
],
swiftSettings: [
.swiftLanguageMode(.v6)
]
),
// swift-corelibs-foundation has a copy of XCTest's sources so:
// (1) we do not depend on the toolchain's XCTest, which depends on toolchain's Foundation, which we cannot pull in at the same time as a Foundation package
// (2) we do not depend on a swift-corelibs-xctest Swift package, which depends on Foundation, which causes a circular dependency in swiftpm
// We believe Foundation is the only project that needs to take this rather drastic measure.
// We also have a stub for swift-testing for the same purpose, but without an implementation since this package has no swift-testing style tests
.target(
name: "XCTest",
dependencies: [
"Foundation"
],
path: "Sources/XCTest"
),
.target(
name: "Testing",
dependencies: [],
path: "Sources/Testing"
),
.testTarget(
name: "TestFoundation",
dependencies: [
"Foundation",
"FoundationXML",
"FoundationNetworking",
"XCTest",
"Testing",
.target(name: "xdgTestHelper", condition: .when(platforms: [.linux, .android]))
],
resources: [
.copy("Foundation/Resources")
],
swiftSettings: [
.define("NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT"),
.swiftLanguageMode(.v6)
]
),
]
)