33import Foundation
44import PackageDescription
55
6- /// Swift settings that should be applied to every Swift target.
7- var globalSwiftSettings : [ SwiftSetting ] {
8- var result : [ SwiftSetting ] = [
9- . enableUpcomingFeature( " InternalImportsByDefault " ) ,
10- . enableUpcomingFeature( " MemberImportVisibility " ) ,
11- . enableUpcomingFeature( " InferIsolatedConformances " ) ,
12- . enableUpcomingFeature( " NonisolatedNonsendingByDefault " ) ,
13- ]
14- if noSwiftPMDependency {
15- result += [ . define( " NO_SWIFTPM_DEPENDENCY " ) ]
16- }
17- return result
18- }
19-
206var products : [ Product ] = [
217 . executable( name: " sourcekit-lsp " , targets: [ " sourcekit-lsp " ] ) ,
228 . library( name: " _SourceKitLSP " , targets: [ " SourceKitLSP " ] ) ,
@@ -50,7 +36,6 @@ var targets: [Target] = [
5036 . product( name: " SwiftToolsSupport-auto " , package : " swift-tools-support-core " ) ,
5137 ] ,
5238 exclude: [ " CMakeLists.txt " ] ,
53- swiftSettings: globalSwiftSettings,
5439 linkerSettings: sourcekitLSPLinkSettings
5540 ) ,
5641
@@ -78,7 +63,6 @@ var targets: [Target] = [
7863 . product( name: " SwiftPMDataModel-auto " , package : " swift-package-manager " ) ,
7964 ] ) ,
8065 exclude: [ " CMakeLists.txt " ] ,
81- swiftSettings: globalSwiftSettings
8266 ) ,
8367
8468 . testTarget(
@@ -92,7 +76,6 @@ var targets: [Target] = [
9276 " TSCExtensions " ,
9377 . product( name: " LanguageServerProtocol " , package : " swift-tools-protocols " ) ,
9478 ] ,
95- swiftSettings: globalSwiftSettings
9679 ) ,
9780
9881 . target(
@@ -118,7 +101,6 @@ var targets: [Target] = [
118101 . product( name: " ToolsProtocolsSwiftExtensions " , package : " swift-tools-protocols " ) ,
119102 ] + swiftSyntaxDependencies( [ " SwiftSyntax " ] ) ,
120103 exclude: [ " CMakeLists.txt " ] ,
121- swiftSettings: globalSwiftSettings
122104 ) ,
123105
124106 // MARK: CompletionScoring
@@ -127,26 +109,22 @@ var targets: [Target] = [
127109 name: " CompletionScoring " ,
128110 dependencies: [ " CCompletionScoring " ] ,
129111 exclude: [ " CMakeLists.txt " ] ,
130- swiftSettings: globalSwiftSettings
131112 ) ,
132113
133114 . target(
134115 name: " CompletionScoringForPlugin " ,
135116 dependencies: [ " CCompletionScoring " ] ,
136117 exclude: [ " CMakeLists.txt " ] ,
137- swiftSettings: globalSwiftSettings
138118 ) ,
139119
140120 . testTarget(
141121 name: " CompletionScoringTests " ,
142122 dependencies: [ " CompletionScoring " , " CompletionScoringTestSupport " , " SwiftExtensions " ] ,
143- swiftSettings: globalSwiftSettings
144123 ) ,
145124
146125 . testTarget(
147126 name: " CompletionScoringPerfTests " ,
148127 dependencies: [ " CompletionScoring " , " CompletionScoringTestSupport " , " SwiftExtensions " ] ,
149- swiftSettings: globalSwiftSettings
150128 ) ,
151129
152130 // MARK: CompletionScoringTestSupport
@@ -159,7 +137,6 @@ var targets: [Target] = [
159137 . product( name: " ToolsProtocolsSwiftExtensions " , package : " swift-tools-protocols " ) ,
160138 ] ,
161139 resources: [ . copy( " INPUTS " ) ] ,
162- swiftSettings: globalSwiftSettings
163140 ) ,
164141
165142 // MARK: CSKTestSupport
@@ -198,7 +175,6 @@ var targets: [Target] = [
198175 . product( name: " ToolsProtocolsSwiftExtensions " , package : " swift-tools-protocols " ) ,
199176 ] + swiftSyntaxDependencies( [ " SwiftIDEUtils " , " SwiftSyntax " , " SwiftParser " ] ) ,
200177 exclude: [ " CMakeLists.txt " ] ,
201- swiftSettings: globalSwiftSettings
202178 ) ,
203179
204180 . testTarget(
@@ -212,7 +188,6 @@ var targets: [Target] = [
212188 . product( name: " SKLogging " , package : " swift-tools-protocols " ) ,
213189 . product( name: " SwiftToolsSupport-auto " , package : " swift-tools-support-core " ) ,
214190 ] ,
215- swiftSettings: globalSwiftSettings
216191 ) ,
217192
218193 // MARK: DocumentationLanguageService
@@ -234,7 +209,6 @@ var targets: [Target] = [
234209 . product( name: " SymbolKit " , package : " swift-docc-symbolkit " ) ,
235210 ] ,
236211 exclude: [ ] ,
237- swiftSettings: globalSwiftSettings
238212 ) ,
239213
240214 // MARK: InProcessClient
@@ -255,7 +229,6 @@ var targets: [Target] = [
255229 . product( name: " ToolsProtocolsSwiftExtensions " , package : " swift-tools-protocols " ) ,
256230 ] ,
257231 exclude: [ " CMakeLists.txt " ] ,
258- swiftSettings: globalSwiftSettings
259232 ) ,
260233
261234 // MARK: LanguageServerProtocolExtensions
@@ -272,7 +245,6 @@ var targets: [Target] = [
272245 . product( name: " ToolsProtocolsSwiftExtensions " , package : " swift-tools-protocols " ) ,
273246 ] ,
274247 exclude: [ " CMakeLists.txt " ] ,
275- swiftSettings: globalSwiftSettings
276248 ) ,
277249
278250 // MARK: SemanticIndex
@@ -292,7 +264,6 @@ var targets: [Target] = [
292264 . product( name: " ToolsProtocolsSwiftExtensions " , package : " swift-tools-protocols " ) ,
293265 ] ,
294266 exclude: [ " CMakeLists.txt " ] ,
295- swiftSettings: globalSwiftSettings
296267 ) ,
297268
298269 . testTarget(
@@ -303,7 +274,6 @@ var targets: [Target] = [
303274 . product( name: " SKLogging " , package : " swift-tools-protocols " ) ,
304275 . product( name: " ToolsProtocolsSwiftExtensions " , package : " swift-tools-protocols " ) ,
305276 ] ,
306- swiftSettings: globalSwiftSettings
307277 ) ,
308278
309279 // MARK: SKOptions
@@ -317,7 +287,6 @@ var targets: [Target] = [
317287 . product( name: " SwiftToolsSupport-auto " , package : " swift-tools-support-core " ) ,
318288 ] ,
319289 exclude: [ " CMakeLists.txt " ] ,
320- swiftSettings: globalSwiftSettings
321290 ) ,
322291
323292 // MARK: SKUtilities
@@ -329,7 +298,6 @@ var targets: [Target] = [
329298 . product( name: " SKLogging " , package : " swift-tools-protocols " ) ,
330299 ] ,
331300 exclude: [ " CMakeLists.txt " ] ,
332- swiftSettings: globalSwiftSettings
333301 ) ,
334302
335303 . target(
@@ -339,7 +307,7 @@ var targets: [Target] = [
339307 . product( name: " _SKLoggingForPlugin " , package : " swift-tools-protocols " ) ,
340308 ] ,
341309 exclude: [ " CMakeLists.txt " ] ,
342- swiftSettings: globalSwiftSettings + [
310+ swiftSettings: [
343311 . unsafeFlags( [
344312 " -module-alias " , " SKLogging=_SKLoggingForPlugin " ,
345313 " -module-alias " , " SwiftExtensions=SwiftExtensionsForPlugin " ,
@@ -354,7 +322,6 @@ var targets: [Target] = [
354322 " SKUtilities " ,
355323 " SKTestSupport " ,
356324 ] ,
357- swiftSettings: globalSwiftSettings
358325 ) ,
359326
360327 // MARK: SKTestSupport
@@ -382,7 +349,6 @@ var targets: [Target] = [
382349 . product( name: " ToolsProtocolsSwiftExtensions " , package : " swift-tools-protocols " ) ,
383350 ] ,
384351 resources: [ . copy( " INPUTS " ) ] ,
385- swiftSettings: globalSwiftSettings
386352 ) ,
387353
388354 // MARK: SourceKitD
@@ -396,7 +362,6 @@ var targets: [Target] = [
396362 . product( name: " ToolsProtocolsSwiftExtensions " , package : " swift-tools-protocols " ) ,
397363 ] ,
398364 exclude: [ " CMakeLists.txt " , " sourcekitd_uids.swift.gyb " ] ,
399- swiftSettings: globalSwiftSettings
400365 ) ,
401366
402367 . target(
@@ -408,7 +373,7 @@ var targets: [Target] = [
408373 . product( name: " _ToolsProtocolsSwiftExtensionsForPlugin " , package : " swift-tools-protocols " ) ,
409374 ] ,
410375 exclude: [ " CMakeLists.txt " , " sourcekitd_uids.swift.gyb " ] ,
411- swiftSettings: globalSwiftSettings + [
376+ swiftSettings: [
412377 . unsafeFlags( [
413378 " -module-alias " , " SKLogging=_SKLoggingForPlugin " ,
414379 " -module-alias " , " SwiftExtensions=SwiftExtensionsForPlugin " ,
@@ -427,7 +392,6 @@ var targets: [Target] = [
427392 " ToolchainRegistry " ,
428393 . product( name: " ToolsProtocolsSwiftExtensions " , package : " swift-tools-protocols " ) ,
429394 ] ,
430- swiftSettings: globalSwiftSettings
431395 ) ,
432396
433397 // MARK: SourceKitLSP
@@ -453,7 +417,6 @@ var targets: [Target] = [
453417 . product( name: " ToolsProtocolsSwiftExtensions " , package : " swift-tools-protocols " ) ,
454418 ] + swiftSyntaxDependencies( [ " SwiftSyntax " ] ) ,
455419 exclude: [ " CMakeLists.txt " ] ,
456- swiftSettings: globalSwiftSettings
457420 ) ,
458421
459422 . testTarget(
@@ -481,7 +444,6 @@ var targets: [Target] = [
481444 + swiftSyntaxDependencies( [
482445 " SwiftIfConfig " , " SwiftParser " , " SwiftSyntax " , " SwiftCompilerPlugin " , " SwiftSyntaxMacros " ,
483446 ] ) ,
484- swiftSettings: globalSwiftSettings
485447 ) ,
486448
487449 // MARK: SwiftExtensions
@@ -492,7 +454,6 @@ var targets: [Target] = [
492454 . product( name: " ToolsProtocolsSwiftExtensions " , package : " swift-tools-protocols " )
493455 ] ,
494456 exclude: [ " CMakeLists.txt " ] ,
495- swiftSettings: globalSwiftSettings
496457 ) ,
497458
498459 . target(
@@ -501,7 +462,7 @@ var targets: [Target] = [
501462 . product( name: " _ToolsProtocolsSwiftExtensionsForPlugin " , package : " swift-tools-protocols " )
502463 ] ,
503464 exclude: [ " CMakeLists.txt " ] ,
504- swiftSettings: globalSwiftSettings + [
465+ swiftSettings: [
505466 . unsafeFlags( [
506467 " -module-alias " , " ToolsProtocolsSwiftExtensions=_ToolsProtocolsSwiftExtensionsForPlugin " ,
507468 ] )
@@ -516,7 +477,6 @@ var targets: [Target] = [
516477 . product( name: " SKLogging " , package : " swift-tools-protocols " ) ,
517478 . product( name: " ToolsProtocolsSwiftExtensions " , package : " swift-tools-protocols " ) ,
518479 ] ,
519- swiftSettings: globalSwiftSettings
520480 ) ,
521481
522482 // MARK: SwiftLanguageService
@@ -555,7 +515,6 @@ var targets: [Target] = [
555515 " SwiftSyntaxBuilder " ,
556516 ] ) ,
557517 exclude: [ " CMakeLists.txt " ] ,
558- swiftSettings: globalSwiftSettings
559518 ) ,
560519
561520 // MARK: SwiftSourceKitClientPlugin
@@ -569,7 +528,7 @@ var targets: [Target] = [
569528 " SwiftSourceKitPluginCommon " ,
570529 ] ,
571530 exclude: [ " CMakeLists.txt " ] ,
572- swiftSettings: globalSwiftSettings + [
531+ swiftSettings: [
573532 . unsafeFlags( [
574533 " -module-alias " , " SourceKitD=SourceKitDForPlugin " ,
575534 " -module-alias " , " SwiftExtensions=SwiftExtensionsForPlugin " ,
@@ -590,7 +549,7 @@ var targets: [Target] = [
590549 . product( name: " _SKLoggingForPlugin " , package : " swift-tools-protocols " ) ,
591550 ] ,
592551 exclude: [ " CMakeLists.txt " ] ,
593- swiftSettings: globalSwiftSettings + [
552+ swiftSettings: [
594553 . unsafeFlags( [
595554 " -module-alias " , " SourceKitD=SourceKitDForPlugin " ,
596555 " -module-alias " , " SwiftExtensions=SwiftExtensionsForPlugin " ,
@@ -615,7 +574,7 @@ var targets: [Target] = [
615574 . product( name: " _ToolsProtocolsSwiftExtensionsForPlugin " , package : " swift-tools-protocols " ) ,
616575 ] ,
617576 exclude: [ " CMakeLists.txt " ] ,
618- swiftSettings: globalSwiftSettings + [
577+ swiftSettings: [
619578 . unsafeFlags( [
620579 " -module-alias " , " CompletionScoring=CompletionScoringForPlugin " ,
621580 " -module-alias " , " SKUtilities=SKUtilitiesForPlugin " ,
@@ -640,7 +599,6 @@ var targets: [Target] = [
640599 " ToolchainRegistry " ,
641600 . product( name: " LanguageServerProtocol " , package : " swift-tools-protocols " ) ,
642601 ] ,
643- swiftSettings: globalSwiftSettings
644602 ) ,
645603
646604 // MARK: ToolchainRegistry
@@ -654,7 +612,6 @@ var targets: [Target] = [
654612 . product( name: " SKLogging " , package : " swift-tools-protocols " ) ,
655613 ] ,
656614 exclude: [ " CMakeLists.txt " ] ,
657- swiftSettings: globalSwiftSettings
658615 ) ,
659616
660617 . testTarget(
@@ -663,7 +620,6 @@ var targets: [Target] = [
663620 " SKTestSupport " ,
664621 " ToolchainRegistry " ,
665622 ] ,
666- swiftSettings: globalSwiftSettings
667623 ) ,
668624
669625 // MARK: TSCExtensions
@@ -677,7 +633,6 @@ var targets: [Target] = [
677633 . product( name: " ToolsProtocolsSwiftExtensions " , package : " swift-tools-protocols " ) ,
678634 ] ,
679635 exclude: [ " CMakeLists.txt " ] ,
680- swiftSettings: globalSwiftSettings
681636 ) ,
682637
683638 . testTarget(
@@ -688,10 +643,39 @@ var targets: [Target] = [
688643 " TSCExtensions " ,
689644 . product( name: " ToolsProtocolsSwiftExtensions " , package : " swift-tools-protocols " ) ,
690645 ] ,
691- swiftSettings: globalSwiftSettings
692646 ) ,
693647]
694648
649+ // MARK: - Apply global Swift settings
650+
651+ // Apply global Swift settings to targets.
652+ do {
653+ var globalSwiftSettings : [ SwiftSetting ] = [
654+ // Swift 7 mode upcoming features. These must be compatible with swift-tools-version.
655+ . enableUpcomingFeature( " InternalImportsByDefault " ) ,
656+ . enableUpcomingFeature( " MemberImportVisibility " ) ,
657+ . enableUpcomingFeature( " InferIsolatedConformances " ) ,
658+ . enableUpcomingFeature( " NonisolatedNonsendingByDefault " ) ,
659+ . enableUpcomingFeature( " ExistentialAny " ) ,
660+ . enableUpcomingFeature( " ImmutableWeakCaptures " ) ,
661+
662+ // Warning escalation.
663+ . unsafeFlags( [ " -Werror " , " ExistentialAny " ] ) ,
664+ ]
665+ if noSwiftPMDependency {
666+ globalSwiftSettings. append ( . define( " NO_SWIFTPM_DEPENDENCY " ) )
667+ }
668+
669+ for target in targets where target. type != . plugin {
670+ if let swiftSettings = target. swiftSettings {
671+ // Target-specific settings should come last.
672+ target. swiftSettings = globalSwiftSettings + swiftSettings
673+ } else {
674+ target. swiftSettings = globalSwiftSettings
675+ }
676+ }
677+ }
678+
695679if buildOnlyTests {
696680 products = [ ]
697681 targets = targets. compactMap { target in
0 commit comments