@@ -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 {
@@ -208,7 +208,7 @@ let package = Package(
208
208
// The Foundation module only has Library Evolution enabled on Apple
209
209
// platforms, and since this target's module publicly imports Foundation,
210
210
// it can only enable Library Evolution itself on those platforms.
211
- swiftSettings: . packageSettings + . enableLibraryEvolution( applePlatformsOnly : true )
211
+ swiftSettings: . packageSettings + . enableLibraryEvolution( . whenApple ( ) )
212
212
) ,
213
213
214
214
// Utility targets: These are utilities intended for use when developing
@@ -244,11 +244,11 @@ extension BuildSettingCondition {
244
244
/// Swift.
245
245
///
246
246
/// - Parameters:
247
- /// - nonEmbeddedCondition: The value to return if the target is not
248
- /// Embedded Swift. If `nil`, the build condition evaluates to `false`.
247
+ /// - nonEmbeddedCondition: The value to return if the target is not
248
+ /// Embedded Swift. If `nil`, the build condition evaluates to `false`.
249
249
///
250
250
/// - Returns: A build setting condition that evaluates to `true` for Embedded
251
- /// Swift or is equal to `nonEmbeddedCondition` for non-Embedded Swift.
251
+ /// Swift or is equal to `nonEmbeddedCondition` for non-Embedded Swift.
252
252
static func whenEmbedded( or nonEmbeddedCondition: @autoclosure ( ) -> Self ? = nil ) -> Self ? {
253
253
if !buildingForEmbedded {
254
254
if let nonEmbeddedCondition = nonEmbeddedCondition ( ) {
@@ -263,6 +263,21 @@ extension BuildSettingCondition {
263
263
nil
264
264
}
265
265
}
266
+
267
+ /// A build setting condition representing all Apple or non-Apple platforms.
268
+ ///
269
+ /// - Parameters:
270
+ /// - isApple: Whether or not the result represents Apple platforms.
271
+ ///
272
+ /// - Returns: A build setting condition that evaluates to `isApple` for Apple
273
+ /// platforms.
274
+ static func whenApple( _ isApple: Bool = true ) -> Self {
275
+ if isApple {
276
+ . when( platforms: [ . macOS, . iOS, . macCatalyst, . watchOS, . tvOS, . visionOS] )
277
+ } else {
278
+ . when( platforms: [ . linux, . custom( " freebsd " ) , . openbsd, . windows, . wasi, . android] )
279
+ }
280
+ }
266
281
}
267
282
268
283
extension Array where Element == PackageDescription . SwiftSetting {
@@ -312,13 +327,14 @@ extension Array where Element == PackageDescription.SwiftSetting {
312
327
// executable rather than a library.
313
328
. define( " SWT_NO_LIBRARY_MACRO_PLUGINS " ) ,
314
329
315
- . define( " SWT_TARGET_OS_APPLE " , . when ( platforms : [ . macOS , . iOS , . macCatalyst , . watchOS , . tvOS , . visionOS ] ) ) ,
330
+ . define( " SWT_TARGET_OS_APPLE " , . whenApple ( ) ) ,
316
331
317
332
. define( " SWT_NO_EXIT_TESTS " , . whenEmbedded( or: . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ) ,
318
333
. define( " SWT_NO_PROCESS_SPAWNING " , . whenEmbedded( or: . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ) ,
319
- . define( " SWT_NO_SNAPSHOT_TYPES " , . whenEmbedded( or: . when ( platforms : [ . linux , . custom ( " freebsd " ) , . openbsd , . windows , . wasi , . android ] ) ) ) ,
334
+ . define( " SWT_NO_SNAPSHOT_TYPES " , . whenEmbedded( or: . whenApple ( false ) ) ) ,
320
335
. define( " SWT_NO_DYNAMIC_LINKING " , . whenEmbedded( or: . when( platforms: [ . wasi] ) ) ) ,
321
336
. define( " SWT_NO_PIPES " , . whenEmbedded( or: . when( platforms: [ . wasi] ) ) ) ,
337
+ . define( " SWT_NO_FOUNDATION_FILE_COORDINATION " , . whenEmbedded( or: . whenApple( false ) ) ) ,
322
338
323
339
. define( " SWT_NO_LEGACY_TEST_DISCOVERY " , . whenEmbedded( ) ) ,
324
340
. define( " SWT_NO_LIBDISPATCH " , . whenEmbedded( ) ) ,
@@ -354,20 +370,16 @@ extension Array where Element == PackageDescription.SwiftSetting {
354
370
]
355
371
}
356
372
357
- /// Create a Swift setting which enables Library Evolution, optionally
358
- /// constraining it to only Apple platforms.
373
+ /// Create a Swift setting which enables Library Evolution.
359
374
///
360
375
/// - Parameters:
361
- /// - applePlatformsOnly: Whether to constrain this setting to only Apple
362
- /// platforms.
363
- static func enableLibraryEvolution( applePlatformsOnly: Bool = false ) -> Self {
376
+ /// - condition: A build setting condition to apply to this setting.
377
+ ///
378
+ /// - Returns: A Swift setting that enables Library Evolution.
379
+ static func enableLibraryEvolution( _ condition: BuildSettingCondition ? = nil ) -> Self {
364
380
var result = [ PackageDescription . SwiftSetting] ( )
365
381
366
382
if buildingForDevelopment {
367
- var condition : BuildSettingCondition ?
368
- if applePlatformsOnly {
369
- condition = . when( platforms: [ . macOS, . iOS, . macCatalyst, . watchOS, . tvOS, . visionOS] )
370
- }
371
383
result. append ( . unsafeFlags( [ " -enable-library-evolution " ] , condition) )
372
384
}
373
385
@@ -410,9 +422,10 @@ extension Array where Element == PackageDescription.CXXSetting {
410
422
result += [
411
423
. define( " SWT_NO_EXIT_TESTS " , . whenEmbedded( or: . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ) ,
412
424
. define( " SWT_NO_PROCESS_SPAWNING " , . whenEmbedded( or: . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ) ,
413
- . define( " SWT_NO_SNAPSHOT_TYPES " , . whenEmbedded( or: . when ( platforms : [ . linux , . custom ( " freebsd " ) , . openbsd , . windows , . wasi , . android ] ) ) ) ,
425
+ . define( " SWT_NO_SNAPSHOT_TYPES " , . whenEmbedded( or: . whenApple ( false ) ) ) ,
414
426
. define( " SWT_NO_DYNAMIC_LINKING " , . whenEmbedded( or: . when( platforms: [ . wasi] ) ) ) ,
415
427
. define( " SWT_NO_PIPES " , . whenEmbedded( or: . when( platforms: [ . wasi] ) ) ) ,
428
+ . define( " SWT_NO_FOUNDATION_FILE_COORDINATION " , . whenEmbedded( or: . whenApple( false ) ) ) ,
416
429
417
430
. define( " SWT_NO_LEGACY_TEST_DISCOVERY " , . whenEmbedded( ) ) ,
418
431
. define( " SWT_NO_LIBDISPATCH " , . whenEmbedded( ) ) ,
0 commit comments