@@ -27,7 +27,7 @@ let buildingForDevelopment = (git?.currentTag == nil)
2727/// to change in the future.
2828///
2929/// - 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.
3131/// ([swift-syntax-#8431](https://github.com/swiftlang/swift-package-manager/issues/8431))
3232let buildingForEmbedded : Bool = {
3333 guard let envvar = Context . environment [ " SWT_EMBEDDED " ] else {
@@ -193,7 +193,7 @@ let package = Package(
193193 // The Foundation module only has Library Evolution enabled on Apple
194194 // platforms, and since this target's module publicly imports Foundation,
195195 // it can only enable Library Evolution itself on those platforms.
196- swiftSettings: . packageSettings + . enableLibraryEvolution( applePlatformsOnly : true )
196+ swiftSettings: . packageSettings + . enableLibraryEvolution( . whenApple ( ) )
197197 ) ,
198198
199199 // Utility targets: These are utilities intended for use when developing
@@ -229,11 +229,11 @@ extension BuildSettingCondition {
229229 /// Swift.
230230 ///
231231 /// - 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`.
234234 ///
235235 /// - 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.
237237 static func whenEmbedded( or nonEmbeddedCondition: @autoclosure ( ) -> Self ? = nil ) -> Self ? {
238238 if !buildingForEmbedded {
239239 if let nonEmbeddedCondition = nonEmbeddedCondition ( ) {
@@ -248,6 +248,21 @@ extension BuildSettingCondition {
248248 nil
249249 }
250250 }
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+ }
251266}
252267
253268extension Array where Element == PackageDescription . SwiftSetting {
@@ -292,13 +307,14 @@ extension Array where Element == PackageDescription.SwiftSetting {
292307 // executable rather than a library.
293308 . define( " SWT_NO_LIBRARY_MACRO_PLUGINS " ) ,
294309
295- . define( " SWT_TARGET_OS_APPLE " , . when ( platforms : [ . macOS , . iOS , . macCatalyst , . watchOS , . tvOS , . visionOS ] ) ) ,
310+ . define( " SWT_TARGET_OS_APPLE " , . whenApple ( ) ) ,
296311
297312 . define( " SWT_NO_EXIT_TESTS " , . whenEmbedded( or: . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ) ,
298313 . 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 ) ) ) ,
300315 . define( " SWT_NO_DYNAMIC_LINKING " , . whenEmbedded( or: . when( platforms: [ . wasi] ) ) ) ,
301316 . define( " SWT_NO_PIPES " , . whenEmbedded( or: . when( platforms: [ . wasi] ) ) ) ,
317+ . define( " SWT_NO_FOUNDATION_FILE_COORDINATION " , . whenEmbedded( or: . whenApple( false ) ) ) ,
302318
303319 . define( " SWT_NO_LEGACY_TEST_DISCOVERY " , . whenEmbedded( ) ) ,
304320 . define( " SWT_NO_LIBDISPATCH " , . whenEmbedded( ) ) ,
@@ -334,20 +350,16 @@ extension Array where Element == PackageDescription.SwiftSetting {
334350 ]
335351 }
336352
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.
339354 ///
340355 /// - 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 {
344360 var result = [ PackageDescription . SwiftSetting] ( )
345361
346362 if buildingForDevelopment {
347- var condition : BuildSettingCondition ?
348- if applePlatformsOnly {
349- condition = . when( platforms: [ . macOS, . iOS, . macCatalyst, . watchOS, . tvOS, . visionOS] )
350- }
351363 result. append ( . unsafeFlags( [ " -enable-library-evolution " ] , condition) )
352364 }
353365
@@ -364,9 +376,10 @@ extension Array where Element == PackageDescription.CXXSetting {
364376 result += [
365377 . define( " SWT_NO_EXIT_TESTS " , . whenEmbedded( or: . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ) ,
366378 . 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 ) ) ) ,
368380 . define( " SWT_NO_DYNAMIC_LINKING " , . whenEmbedded( or: . when( platforms: [ . wasi] ) ) ) ,
369381 . define( " SWT_NO_PIPES " , . whenEmbedded( or: . when( platforms: [ . wasi] ) ) ) ,
382+ . define( " SWT_NO_FOUNDATION_FILE_COORDINATION " , . whenEmbedded( or: . whenApple( false ) ) ) ,
370383
371384 . define( " SWT_NO_LEGACY_TEST_DISCOVERY " , . whenEmbedded( ) ) ,
372385 . define( " SWT_NO_LIBDISPATCH " , . whenEmbedded( ) ) ,
0 commit comments