@@ -147,9 +147,7 @@ let package = Package(
147147 . define( " GLES_SILENCE_DEPRECATION " ,
148148 . when( platforms: [ . iOS, . tvOS] ) ) ,
149149 ] ,
150- swiftSettings: {
151- var settings : [ SwiftSetting ] = [ ]
152-
150+ swiftSettings: . default( withCustomization: { settings in
153151 settings. append (
154152 . define( " GATEENGINE_USE_OPENAL " , . when( platforms: [ . linux] ) )
155153 )
@@ -189,33 +187,6 @@ let package = Package(
189187 . define( " GATEENGINE_PLATFORM_SUPPORTS_FOUNDATION_FILEMANAGER " ,
190188 . when( platforms: . any( except: . wasi) ) ) ,
191189 ] )
192-
193- #if true // Experimental and upcomming language features.
194- // These should be disabled for releases.
195- // These are to get a headstart on the next Swift versions.
196- // https://www.swift.org/swift-evolution/#?upcoming=true
197- settings. append ( contentsOf: [
198- . enableUpcomingFeature( " IsolatedDefaultValues " ) ,
199- . enableUpcomingFeature( " InternalImportsByDefault " ) ,
200- . enableUpcomingFeature( " DisableOutwardActorInference " ) ,
201- . enableUpcomingFeature( " ImportObjcForwardDeclarations " ) ,
202- . enableUpcomingFeature( " BareSlashRegexLiterals " ) ,
203- . enableUpcomingFeature( " ExistentialAny " ) ,
204- . enableUpcomingFeature( " ForwardTrailingClosures " ) ,
205- . enableUpcomingFeature( " ConciseMagicFile " ) ,
206- . enableUpcomingFeature( " DynamicActorIsolation " ) ,
207- . enableUpcomingFeature( " FullTypedThrows " ) ,
208- . enableUpcomingFeature( " InferSendableFromCaptures " ) ,
209- . enableUpcomingFeature( " DeprecateApplicationMain " ) ,
210-
211- . enableExperimentalFeature( " AccessLevelOnImport " ) ,
212- . enableExperimentalFeature( " StrictConcurrency " ) ,
213- ] )
214- #if swift(>=6.2)
215- settings. append ( . enableExperimentalFeature( " IsolatedDeinit " ) )
216- #endif
217- #endif
218-
219190
220191 #if HTML5
221192 // Options for development of WASI platform
@@ -241,8 +212,7 @@ let package = Package(
241212 //.define("GATEENGINE_FORCE_OPNEGL_APPLE", .when(platforms: [.macOS, /*.iOS, .tvOS*/])),
242213 ] )
243214 #endif
244- return settings
245- } ( ) ,
215+ } ) ,
246216 plugins: [
247217 //.plugin(name: "SwiftLintPlugin", package: "SwiftLint"),
248218 ] ) ,
@@ -252,27 +222,23 @@ let package = Package(
252222 " GameMath " ,
253223 . product( name: " Collections " , package : " swift-collections " )
254224 ] ,
255- swiftSettings: [
256- . define( " GATEENGINE_DEBUG_SHADERS " , . when( configuration: . debug) )
257- ] ) ,
225+ swiftSettings: . default ( withCustomization : { settings in
226+ settings . append ( . define( " GATEENGINE_DEBUG_SHADERS " , . when( configuration: . debug) ) )
227+ } ) ) ,
258228
259- . target( name: " GameMath " , swiftSettings: {
260- var array : [ SwiftSetting ] = [ ]
261-
229+ . target( name: " GameMath " , swiftSettings: . default( withCustomization: { settings in
262230 #if false
263231 // Possibly faster on old hardware, but less accurate.
264232 // There is no reason to use this on modern hardware.
265- array . append ( . define( " GameMathUseFastInverseSquareRoot " ) )
233+ settings . append ( . define( " GameMathUseFastInverseSquareRoot " ) )
266234 #endif
267235
268236 // These settings are faster only with optimization.
269237 #if true
270- array . append ( . define( " GameMathUseSIMD " , . when( configuration: . release, traits: [ " SIMD " ] ) ) )
271- array . append ( . define( " GameMathUseLoopVectorization " , . when( configuration: . release) ) )
238+ settings . append ( . define( " GameMathUseSIMD " , . when( configuration: . release, traits: [ " SIMD " ] ) ) )
239+ settings . append ( . define( " GameMathUseLoopVectorization " , . when( configuration: . release) ) )
272240 #endif
273-
274- return array. isEmpty ? nil : array
275- } ( ) ) ,
241+ } ) ) ,
276242 ] )
277243
278244 // MARK: - Macros
@@ -351,9 +317,9 @@ let package = Package(
351317 // Direct3D12
352318 . target( name: " Direct3D12 " ,
353319 path: " Dependencies/Direct3D12 " ,
354- swiftSettings: [
355- . define( " Direct3D12ExcludeOriginalStyleAPI " , . when( configuration: . release) ) ,
356- ] ) ,
320+ swiftSettings: . default ( withCustomization : { settings in
321+ settings . append ( . define( " Direct3D12ExcludeOriginalStyleAPI " , . when( configuration: . release) ) )
322+ } ) ) ,
357323 // XAudio2
358324 . target( name: " XAudio2 " ,
359325 dependencies: [ " XAudio2C " ] ,
@@ -418,9 +384,9 @@ let package = Package(
418384 . testTarget( name: " GateEngineTests " ,
419385 dependencies: [ " GateEngine " ] ,
420386 resources: [ . copy( " Resources " ) ] ,
421- swiftSettings: [
422- . define( " DISABLE_GRAVITY_TESTS " , . when( platforms: [ . wasi] ) ) ,
423- ] ) ,
387+ swiftSettings: . default ( withCustomization : { settings in
388+ settings . append ( . define( " DISABLE_GRAVITY_TESTS " , . when( platforms: [ . wasi] ) ) )
389+ } ) ) ,
424390 . testTarget( name: " GameMathTests " ,
425391 dependencies: [ " GameMath " ] ) ,
426392 . testTarget( name: " GravityTests " ,
@@ -431,19 +397,19 @@ let package = Package(
431397 . copy( " Resources/infiniteloop " ) ,
432398 . copy( " Resources/unittest " ) ,
433399 ] ,
434- swiftSettings: [
400+ swiftSettings: . default ( withCustomization : { settings in
435401 // https://github.com/STREGAsGate/GateEngine/issues/36
436- . define( " DISABLE_GRAVITY_TESTS " , . when( platforms: [ . wasi] ) ) ,
437- ] ) ,
402+ settings . append ( . define( " DISABLE_GRAVITY_TESTS " , . when( platforms: [ . wasi] ) ) )
403+ } ) ) ,
438404 ] )
439405 #if !os(Windows)
440406 targets. append ( contentsOf: [
441407 . testTarget( name: " GameMathSIMDTests " ,
442408 dependencies: [ " GameMath " ] ,
443- swiftSettings: [
444- . define( " GameMathUseSIMD " ) ,
445- . define( " GameMathUseLoopVectorization " )
446- ] ) ,
409+ swiftSettings: . default ( withCustomization : { settings in
410+ settings . append ( . define( " GameMathUseSIMD " ) )
411+ settings . append ( . define( " GameMathUseLoopVectorization " ) )
412+ } ) ) ,
447413 ] )
448414 #endif
449415
@@ -674,3 +640,94 @@ extension Array where Element == Platform {
674640 }
675641}
676642
643+ extension Array where Element == SwiftSetting {
644+ static var `default` : Self ? {
645+ var settings : Self = [ ]
646+ if let upcommingFeatureFlags = Self . upcommingFeatureFlags {
647+ settings. append ( contentsOf: upcommingFeatureFlags)
648+ }
649+ if let exprimentalFeatureFlags = Self . exprimentalFeatureFlags {
650+ settings. append ( contentsOf: exprimentalFeatureFlags)
651+ }
652+ return settings. isEmpty ? nil : settings
653+ }
654+
655+ static func `default`( withCustomization block: ( _ settings: inout Self ) -> ( ) ) -> Self ? {
656+ var settings : Self = . default ?? [ ]
657+ block ( & settings)
658+ return settings. isEmpty ? nil : settings
659+ }
660+
661+ static var upcommingFeatureFlags : Self ? {
662+ var settings : Self = [ ]
663+ #if compiler(>=6.2)
664+ settings. append ( contentsOf: [
665+ . enableUpcomingFeature( " InferIsolatedConformances " ) ,
666+ . enableUpcomingFeature( " NonisolatedNonsendingByDefault " ) ,
667+ . enableUpcomingFeature( " NonescapableTypes " ) ,
668+ ] )
669+ #endif
670+ #if compiler(>=6.1)
671+ settings. append ( contentsOf: [
672+ . enableUpcomingFeature( " MemberImportVisibility " ) ,
673+ ] )
674+ #endif
675+ #if compiler(>=6.0)
676+ settings. append ( contentsOf: [
677+ . enableUpcomingFeature( " GlobalActorIsolatedTypesUsability " ) ,
678+ . enableUpcomingFeature( " DynamicActorIsolation " ) ,
679+ . enableUpcomingFeature( " InferSendableFromCaptures " ) ,
680+ . enableUpcomingFeature( " RegionBasedIsolation " ) ,
681+ . enableUpcomingFeature( " InternalImportsByDefault " ) ,
682+ ] )
683+ #endif
684+ #if compiler(>=5.10)
685+ settings. append ( contentsOf: [
686+ . enableUpcomingFeature( " GlobalConcurrency " ) ,
687+ . enableUpcomingFeature( " IsolatedDefaultValues " ) ,
688+ . enableUpcomingFeature( " DeprecateApplicationMain " ) ,
689+ ] )
690+ #endif
691+ #if compiler(>=5.9)
692+ settings. append ( contentsOf: [
693+ . enableUpcomingFeature( " DisableOutwardActorInference " ) ,
694+ . enableUpcomingFeature( " ImportObjcForwardDeclarations " ) ,
695+ ] )
696+ #endif
697+ #if compiler(>=5.8)
698+ settings. append ( contentsOf: [
699+ . enableUpcomingFeature( " ConciseMagicFile " ) ,
700+ ] )
701+ #endif
702+ #if compiler(>=5.7)
703+ settings. append ( contentsOf: [
704+ . enableUpcomingFeature( " BareSlashRegexLiterals " ) ,
705+ . enableUpcomingFeature( " ImplicitOpenExistentials " ) ,
706+ ] )
707+ #endif
708+ #if compiler(>=5.6)
709+ settings. append ( contentsOf: [
710+ . enableUpcomingFeature( " StrictConcurrency=complete " ) ,
711+ . enableUpcomingFeature( " ExistentialAny " ) ,
712+ ] )
713+ #endif
714+ #if compiler(>=5.3)
715+ settings. append ( contentsOf: [
716+ . enableUpcomingFeature( " ForwardTrailingClosures " ) ,
717+ ] )
718+ #endif
719+
720+ return settings. isEmpty ? nil : settings
721+ }
722+
723+ static var exprimentalFeatureFlags : Self ? {
724+ var settings : Self = [ ]
725+ #if compiler(>=6.2)
726+ settings. append ( contentsOf: [
727+ . enableExperimentalFeature( " IsolatedDeinit " ) ,
728+ ] )
729+ #endif
730+
731+ return settings. isEmpty ? nil : settings
732+ }
733+ }
0 commit comments