@@ -27,7 +27,7 @@ let buildingForDevelopment = (git?.currentTag == nil)
27
27
/// to change in the future.
28
28
///
29
29
/// - Bug: There is currently no way for us to tell if we are being asked to
30
- /// build for an Embedded Swift target at the package manifest level.
30
+ /// build for an Embedded Swift target at the package manifest level.
31
31
/// ([swift-syntax-#8431](https://github.com/swiftlang/swift-package-manager/issues/8431))
32
32
let buildingForEmbedded : Bool = {
33
33
guard let envvar = Context . environment [ " SWT_EMBEDDED " ] else {
@@ -84,6 +84,19 @@ let package = Package(
84
84
)
85
85
#endif
86
86
87
+ result += [
88
+ . library(
89
+ name: " _Testing_ExperimentalImageAttachments " ,
90
+ targets: [
91
+ " _Testing_AppKit " ,
92
+ " _Testing_CoreGraphics " ,
93
+ " _Testing_CoreImage " ,
94
+ " _Testing_UIKit " ,
95
+ " _Testing_WinSDK " ,
96
+ ]
97
+ )
98
+ ]
99
+
87
100
result. append (
88
101
. library(
89
102
name: " _TestDiscovery " ,
@@ -95,15 +108,16 @@ let package = Package(
95
108
return result
96
109
} ( ) ,
97
110
98
- traits: [
99
- . trait(
100
- name: " ExperimentalExitTestValueCapture " ,
101
- description: " Enable experimental support for capturing values in exit tests "
102
- ) ,
103
- ] ,
104
-
105
111
dependencies: [
106
- . package ( url: " https://github.com/swiftlang/swift-syntax.git " , from: " 602.0.0-latest " ) ,
112
+ // swift-syntax periodically publishes a new tag with a suffix of the format
113
+ // "-prerelease-YYYY-MM-DD". We always want to use the most recent tag
114
+ // associated with a particular Swift version, without needing to hardcode
115
+ // an exact tag and manually keep it up-to-date. Specifying the suffix
116
+ // "-latest" on this dependency is a workaround which causes Swift package
117
+ // manager to use the lexicographically highest-sorted tag with the
118
+ // specified semantic version, meaning the most recent "prerelease" tag will
119
+ // always be used.
120
+ . package ( url: " https://github.com/swiftlang/swift-syntax.git " , from: " 603.0.0-latest " ) ,
107
121
] ,
108
122
109
123
targets: [
@@ -125,10 +139,32 @@ let package = Package(
125
139
name: " TestingTests " ,
126
140
dependencies: [
127
141
" Testing " ,
142
+ " _Testing_AppKit " ,
128
143
" _Testing_CoreGraphics " ,
144
+ " _Testing_CoreImage " ,
129
145
" _Testing_Foundation " ,
146
+ " _Testing_UIKit " ,
147
+ " _Testing_WinSDK " ,
148
+ " MemorySafeTestingTests " ,
130
149
] ,
131
- swiftSettings: . packageSettings
150
+ swiftSettings: . packageSettings,
151
+ linkerSettings: [
152
+ . linkedLibrary( " util " , . when( platforms: [ . openbsd] ) )
153
+ ]
154
+ ) ,
155
+
156
+ // Use a plain `.target` instead of a `.testTarget` to avoid the unnecessary
157
+ // overhead of having a separate test target for this module. Conceptually,
158
+ // the content in this module is no different than content which would
159
+ // typically be placed in the `TestingTests` target, except this content
160
+ // needs the (module-wide) strict memory safety feature to be enabled.
161
+ . target(
162
+ name: " MemorySafeTestingTests " ,
163
+ dependencies: [
164
+ " Testing " ,
165
+ ] ,
166
+ path: " Tests/_MemorySafeTestingTests " ,
167
+ swiftSettings: . packageSettings + . strictMemorySafety
132
168
) ,
133
169
. testTarget(
134
170
name: " SubexpressionShowcase " ,
@@ -182,12 +218,33 @@ let package = Package(
182
218
) ,
183
219
184
220
// Cross-import overlays (not supported by Swift Package Manager)
221
+ . target(
222
+ name: " _Testing_AppKit " ,
223
+ dependencies: [
224
+ " Testing " ,
225
+ " _Testing_CoreGraphics " ,
226
+ ] ,
227
+ path: " Sources/Overlays/_Testing_AppKit " ,
228
+ exclude: [ " CMakeLists.txt " ] ,
229
+ swiftSettings: . packageSettings + . enableLibraryEvolution( )
230
+ ) ,
185
231
. target(
186
232
name: " _Testing_CoreGraphics " ,
187
233
dependencies: [
188
234
" Testing " ,
189
235
] ,
190
236
path: " Sources/Overlays/_Testing_CoreGraphics " ,
237
+ exclude: [ " CMakeLists.txt " ] ,
238
+ swiftSettings: . packageSettings + . enableLibraryEvolution( )
239
+ ) ,
240
+ . target(
241
+ name: " _Testing_CoreImage " ,
242
+ dependencies: [
243
+ " Testing " ,
244
+ " _Testing_CoreGraphics " ,
245
+ ] ,
246
+ path: " Sources/Overlays/_Testing_CoreImage " ,
247
+ exclude: [ " CMakeLists.txt " ] ,
191
248
swiftSettings: . packageSettings + . enableLibraryEvolution( )
192
249
) ,
193
250
. target(
@@ -200,7 +257,26 @@ let package = Package(
200
257
// The Foundation module only has Library Evolution enabled on Apple
201
258
// platforms, and since this target's module publicly imports Foundation,
202
259
// it can only enable Library Evolution itself on those platforms.
203
- swiftSettings: . packageSettings + . enableLibraryEvolution( applePlatformsOnly: true )
260
+ swiftSettings: . packageSettings + . enableLibraryEvolution( . whenApple( ) )
261
+ ) ,
262
+ . target(
263
+ name: " _Testing_UIKit " ,
264
+ dependencies: [
265
+ " Testing " ,
266
+ " _Testing_CoreGraphics " ,
267
+ " _Testing_CoreImage " ,
268
+ ] ,
269
+ path: " Sources/Overlays/_Testing_UIKit " ,
270
+ exclude: [ " CMakeLists.txt " ] ,
271
+ swiftSettings: . packageSettings + . enableLibraryEvolution( )
272
+ ) ,
273
+ . target(
274
+ name: " _Testing_WinSDK " ,
275
+ dependencies: [
276
+ " Testing " ,
277
+ ] ,
278
+ path: " Sources/Overlays/_Testing_WinSDK " ,
279
+ swiftSettings: . packageSettings + . enableLibraryEvolution( )
204
280
) ,
205
281
206
282
// Utility targets: These are utilities intended for use when developing
@@ -236,11 +312,11 @@ extension BuildSettingCondition {
236
312
/// Swift.
237
313
///
238
314
/// - Parameters:
239
- /// - nonEmbeddedCondition: The value to return if the target is not
240
- /// Embedded Swift. If `nil`, the build condition evaluates to `false`.
315
+ /// - nonEmbeddedCondition: The value to return if the target is not
316
+ /// Embedded Swift. If `nil`, the build condition evaluates to `false`.
241
317
///
242
318
/// - Returns: A build setting condition that evaluates to `true` for Embedded
243
- /// Swift or is equal to `nonEmbeddedCondition` for non-Embedded Swift.
319
+ /// Swift or is equal to `nonEmbeddedCondition` for non-Embedded Swift.
244
320
static func whenEmbedded( or nonEmbeddedCondition: @autoclosure ( ) -> Self ? = nil ) -> Self ? {
245
321
if !buildingForEmbedded {
246
322
if let nonEmbeddedCondition = nonEmbeddedCondition ( ) {
@@ -255,6 +331,21 @@ extension BuildSettingCondition {
255
331
nil
256
332
}
257
333
}
334
+
335
+ /// A build setting condition representing all Apple or non-Apple platforms.
336
+ ///
337
+ /// - Parameters:
338
+ /// - isApple: Whether or not the result represents Apple platforms.
339
+ ///
340
+ /// - Returns: A build setting condition that evaluates to `isApple` for Apple
341
+ /// platforms.
342
+ static func whenApple( _ isApple: Bool = true ) -> Self {
343
+ if isApple {
344
+ . when( platforms: [ . macOS, . iOS, . macCatalyst, . watchOS, . tvOS, . visionOS] )
345
+ } else {
346
+ . when( platforms: [ . linux, . custom( " freebsd " ) , . openbsd, . windows, . wasi, . android] )
347
+ }
348
+ }
258
349
}
259
350
260
351
extension Array where Element == PackageDescription . SwiftSetting {
@@ -296,30 +387,25 @@ extension Array where Element == PackageDescription.SwiftSetting {
296
387
// new-enough toolchain.
297
388
. enableExperimentalFeature( " AllowUnsafeAttribute " ) ,
298
389
390
+ . enableUpcomingFeature( " InferIsolatedConformances " ) ,
391
+
299
392
// When building as a package, the macro plugin always builds as an
300
393
// executable rather than a library.
301
394
. define( " SWT_NO_LIBRARY_MACRO_PLUGINS " ) ,
302
395
303
- . define( " SWT_TARGET_OS_APPLE " , . when ( platforms : [ . macOS , . iOS , . macCatalyst , . watchOS , . tvOS , . visionOS ] ) ) ,
396
+ . define( " SWT_TARGET_OS_APPLE " , . whenApple ( ) ) ,
304
397
305
398
. define( " SWT_NO_EXIT_TESTS " , . whenEmbedded( or: . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ) ,
306
399
. define( " SWT_NO_PROCESS_SPAWNING " , . whenEmbedded( or: . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ) ,
307
- . define( " SWT_NO_SNAPSHOT_TYPES " , . whenEmbedded( or: . when ( platforms : [ . linux , . custom ( " freebsd " ) , . openbsd , . windows , . wasi , . android ] ) ) ) ,
400
+ . define( " SWT_NO_SNAPSHOT_TYPES " , . whenEmbedded( or: . whenApple ( false ) ) ) ,
308
401
. define( " SWT_NO_DYNAMIC_LINKING " , . whenEmbedded( or: . when( platforms: [ . wasi] ) ) ) ,
309
402
. define( " SWT_NO_PIPES " , . whenEmbedded( or: . when( platforms: [ . wasi] ) ) ) ,
403
+ . define( " SWT_NO_FOUNDATION_FILE_COORDINATION " , . whenEmbedded( or: . whenApple( false ) ) ) ,
310
404
311
405
. define( " SWT_NO_LEGACY_TEST_DISCOVERY " , . whenEmbedded( ) ) ,
312
406
. define( " SWT_NO_LIBDISPATCH " , . whenEmbedded( ) ) ,
313
407
]
314
408
315
- // Unconditionally enable 'ExperimentalExitTestValueCapture' when building
316
- // for development.
317
- if buildingForDevelopment {
318
- result += [
319
- . define( " ExperimentalExitTestValueCapture " )
320
- ]
321
- }
322
-
323
409
return result
324
410
}
325
411
@@ -342,25 +428,33 @@ extension Array where Element == PackageDescription.SwiftSetting {
342
428
]
343
429
}
344
430
345
- /// Create a Swift setting which enables Library Evolution, optionally
346
- /// constraining it to only Apple platforms.
431
+ /// Create a Swift setting which enables Library Evolution.
347
432
///
348
433
/// - Parameters:
349
- /// - applePlatformsOnly: Whether to constrain this setting to only Apple
350
- /// platforms.
351
- static func enableLibraryEvolution( applePlatformsOnly: Bool = false ) -> Self {
434
+ /// - condition: A build setting condition to apply to this setting.
435
+ ///
436
+ /// - Returns: A Swift setting that enables Library Evolution.
437
+ static func enableLibraryEvolution( _ condition: BuildSettingCondition ? = nil ) -> Self {
352
438
var result = [ PackageDescription . SwiftSetting] ( )
353
439
354
440
if buildingForDevelopment {
355
- var condition : BuildSettingCondition ?
356
- if applePlatformsOnly {
357
- condition = . when( platforms: [ . macOS, . iOS, . macCatalyst, . watchOS, . tvOS, . visionOS] )
358
- }
359
441
result. append ( . unsafeFlags( [ " -enable-library-evolution " ] , condition) )
360
442
}
361
443
362
444
return result
363
445
}
446
+
447
+ /// Settings necessary to enable Strict Memory Safety, introduced in
448
+ /// [SE-0458: Opt-in Strict Memory Safety Checking](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0458-strict-memory-safety.md#swiftpm-integration).
449
+ static var strictMemorySafety : Self {
450
+ #if compiler(>=6.2)
451
+ // FIXME: Adopt official `.strictMemorySafety()` condition once the minimum
452
+ // supported toolchain is 6.2.
453
+ [ . unsafeFlags( [ " -strict-memory-safety " ] ) ]
454
+ #else
455
+ [ ]
456
+ #endif
457
+ }
364
458
}
365
459
366
460
extension Array where Element == PackageDescription . CXXSetting {
@@ -372,9 +466,10 @@ extension Array where Element == PackageDescription.CXXSetting {
372
466
result += [
373
467
. define( " SWT_NO_EXIT_TESTS " , . whenEmbedded( or: . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ) ,
374
468
. define( " SWT_NO_PROCESS_SPAWNING " , . whenEmbedded( or: . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ) ,
375
- . define( " SWT_NO_SNAPSHOT_TYPES " , . whenEmbedded( or: . when ( platforms : [ . linux , . custom ( " freebsd " ) , . openbsd , . windows , . wasi , . android ] ) ) ) ,
469
+ . define( " SWT_NO_SNAPSHOT_TYPES " , . whenEmbedded( or: . whenApple ( false ) ) ) ,
376
470
. define( " SWT_NO_DYNAMIC_LINKING " , . whenEmbedded( or: . when( platforms: [ . wasi] ) ) ) ,
377
471
. define( " SWT_NO_PIPES " , . whenEmbedded( or: . when( platforms: [ . wasi] ) ) ) ,
472
+ . define( " SWT_NO_FOUNDATION_FILE_COORDINATION " , . whenEmbedded( or: . whenApple( false ) ) ) ,
378
473
379
474
. define( " SWT_NO_LEGACY_TEST_DISCOVERY " , . whenEmbedded( ) ) ,
380
475
. define( " SWT_NO_LIBDISPATCH " , . whenEmbedded( ) ) ,
0 commit comments