@@ -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 {
@@ -193,7 +193,7 @@ let package = Package(
193
193
// The Foundation module only has Library Evolution enabled on Apple
194
194
// platforms, and since this target's module publicly imports Foundation,
195
195
// it can only enable Library Evolution itself on those platforms.
196
- swiftSettings: . packageSettings + . enableLibraryEvolution( applePlatformsOnly : true )
196
+ swiftSettings: . packageSettings + . enableLibraryEvolution( . whenApple ( ) )
197
197
) ,
198
198
199
199
// Utility targets: These are utilities intended for use when developing
@@ -229,11 +229,11 @@ extension BuildSettingCondition {
229
229
/// Swift.
230
230
///
231
231
/// - Parameters:
232
- /// - nonEmbeddedCondition: The value to return if the target is not
233
- /// Embedded Swift. If `nil`, the build condition evaluates to `false`.
232
+ /// - nonEmbeddedCondition: The value to return if the target is not
233
+ /// Embedded Swift. If `nil`, the build condition evaluates to `false`.
234
234
///
235
235
/// - Returns: A build setting condition that evaluates to `true` for Embedded
236
- /// Swift or is equal to `nonEmbeddedCondition` for non-Embedded Swift.
236
+ /// Swift or is equal to `nonEmbeddedCondition` for non-Embedded Swift.
237
237
static func whenEmbedded( or nonEmbeddedCondition: @autoclosure ( ) -> Self ? = nil ) -> Self ? {
238
238
if !buildingForEmbedded {
239
239
if let nonEmbeddedCondition = nonEmbeddedCondition ( ) {
@@ -248,6 +248,21 @@ extension BuildSettingCondition {
248
248
nil
249
249
}
250
250
}
251
+
252
+ /// A build setting condition representing all Apple or non-Apple platforms.
253
+ ///
254
+ /// - Parameters:
255
+ /// - isApple: Whether or not the result represents Apple platforms.
256
+ ///
257
+ /// - Returns: A build setting condition that evaluates to `isApple` for Apple
258
+ /// platforms.
259
+ static func whenApple( _ isApple: Bool = true ) -> Self {
260
+ if isApple {
261
+ . when( platforms: [ . macOS, . iOS, . macCatalyst, . watchOS, . tvOS, . visionOS] )
262
+ } else {
263
+ . when( platforms: [ . linux, . custom( " freebsd " ) , . openbsd, . windows, . wasi, . android] )
264
+ }
265
+ }
251
266
}
252
267
253
268
extension Array where Element == PackageDescription . SwiftSetting {
@@ -292,13 +307,14 @@ extension Array where Element == PackageDescription.SwiftSetting {
292
307
// executable rather than a library.
293
308
. define( " SWT_NO_LIBRARY_MACRO_PLUGINS " ) ,
294
309
295
- . define( " SWT_TARGET_OS_APPLE " , . when ( platforms : [ . macOS , . iOS , . macCatalyst , . watchOS , . tvOS , . visionOS ] ) ) ,
310
+ . define( " SWT_TARGET_OS_APPLE " , . whenApple ( ) ) ,
296
311
297
312
. define( " SWT_NO_EXIT_TESTS " , . whenEmbedded( or: . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ) ,
298
313
. define( " SWT_NO_PROCESS_SPAWNING " , . whenEmbedded( or: . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ) ,
299
- . define( " SWT_NO_SNAPSHOT_TYPES " , . whenEmbedded( or: . when ( platforms : [ . linux , . custom ( " freebsd " ) , . openbsd , . windows , . wasi , . android ] ) ) ) ,
314
+ . define( " SWT_NO_SNAPSHOT_TYPES " , . whenEmbedded( or: . whenApple ( false ) ) ) ,
300
315
. define( " SWT_NO_DYNAMIC_LINKING " , . whenEmbedded( or: . when( platforms: [ . wasi] ) ) ) ,
301
316
. define( " SWT_NO_PIPES " , . whenEmbedded( or: . when( platforms: [ . wasi] ) ) ) ,
317
+ . define( " SWT_NO_FOUNDATION_FILE_COORDINATION " , . whenEmbedded( or: . whenApple( false ) ) ) ,
302
318
303
319
. define( " SWT_NO_LEGACY_TEST_DISCOVERY " , . whenEmbedded( ) ) ,
304
320
. define( " SWT_NO_LIBDISPATCH " , . whenEmbedded( ) ) ,
@@ -334,20 +350,16 @@ extension Array where Element == PackageDescription.SwiftSetting {
334
350
]
335
351
}
336
352
337
- /// Create a Swift setting which enables Library Evolution, optionally
338
- /// constraining it to only Apple platforms.
353
+ /// Create a Swift setting which enables Library Evolution.
339
354
///
340
355
/// - Parameters:
341
- /// - applePlatformsOnly: Whether to constrain this setting to only Apple
342
- /// platforms.
343
- static func enableLibraryEvolution( applePlatformsOnly: Bool = false ) -> Self {
356
+ /// - condition: A build setting condition to apply to this setting.
357
+ ///
358
+ /// - Returns: A Swift setting that enables Library Evolution.
359
+ static func enableLibraryEvolution( _ condition: BuildSettingCondition ? = nil ) -> Self {
344
360
var result = [ PackageDescription . SwiftSetting] ( )
345
361
346
362
if buildingForDevelopment {
347
- var condition : BuildSettingCondition ?
348
- if applePlatformsOnly {
349
- condition = . when( platforms: [ . macOS, . iOS, . macCatalyst, . watchOS, . tvOS, . visionOS] )
350
- }
351
363
result. append ( . unsafeFlags( [ " -enable-library-evolution " ] , condition) )
352
364
}
353
365
@@ -364,9 +376,10 @@ extension Array where Element == PackageDescription.CXXSetting {
364
376
result += [
365
377
. define( " SWT_NO_EXIT_TESTS " , . whenEmbedded( or: . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ) ,
366
378
. define( " SWT_NO_PROCESS_SPAWNING " , . whenEmbedded( or: . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ) ,
367
- . define( " SWT_NO_SNAPSHOT_TYPES " , . whenEmbedded( or: . when ( platforms : [ . linux , . custom ( " freebsd " ) , . openbsd , . windows , . wasi , . android ] ) ) ) ,
379
+ . define( " SWT_NO_SNAPSHOT_TYPES " , . whenEmbedded( or: . whenApple ( false ) ) ) ,
368
380
. define( " SWT_NO_DYNAMIC_LINKING " , . whenEmbedded( or: . when( platforms: [ . wasi] ) ) ) ,
369
381
. define( " SWT_NO_PIPES " , . whenEmbedded( or: . when( platforms: [ . wasi] ) ) ) ,
382
+ . define( " SWT_NO_FOUNDATION_FILE_COORDINATION " , . whenEmbedded( or: . whenApple( false ) ) ) ,
370
383
371
384
. define( " SWT_NO_LEGACY_TEST_DISCOVERY " , . whenEmbedded( ) ) ,
372
385
. define( " SWT_NO_LIBDISPATCH " , . whenEmbedded( ) ) ,
0 commit comments