Skip to content

Commit cf2ade6

Browse files
committed
Apply global Swift settings via mutation
1 parent a30c93d commit cf2ade6

File tree

1 file changed

+36
-58
lines changed

1 file changed

+36
-58
lines changed

Package.swift

Lines changed: 36 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,6 @@
33
import Foundation
44
import PackageDescription
55

6-
/// Swift settings that should be applied to every Swift target.
7-
var globalSwiftSettings: [SwiftSetting] {
8-
var result: [SwiftSetting] = [
9-
// Swift 7 mode upcoming features. These must be compatible with swift-tools-version.
10-
.enableUpcomingFeature("InternalImportsByDefault"),
11-
.enableUpcomingFeature("MemberImportVisibility"),
12-
.enableUpcomingFeature("InferIsolatedConformances"),
13-
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
14-
.enableUpcomingFeature("ExistentialAny"),
15-
.enableUpcomingFeature("ImmutableWeakCaptures"),
16-
17-
// Warning escalation.
18-
.unsafeFlags(["-Werror", "ExistentialAny"]),
19-
]
20-
if noSwiftPMDependency {
21-
result += [.define("NO_SWIFTPM_DEPENDENCY")]
22-
}
23-
return result
24-
}
25-
266
var products: [Product] = [
277
.executable(name: "sourcekit-lsp", targets: ["sourcekit-lsp"]),
288
.library(name: "_SourceKitLSP", targets: ["SourceKitLSP"]),
@@ -56,7 +36,6 @@ var targets: [Target] = [
5636
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
5737
],
5838
exclude: ["CMakeLists.txt"],
59-
swiftSettings: globalSwiftSettings,
6039
linkerSettings: sourcekitLSPLinkSettings
6140
),
6241

@@ -84,7 +63,6 @@ var targets: [Target] = [
8463
.product(name: "SwiftPMDataModel-auto", package: "swift-package-manager"),
8564
]),
8665
exclude: ["CMakeLists.txt"],
87-
swiftSettings: globalSwiftSettings
8866
),
8967

9068
.testTarget(
@@ -98,7 +76,6 @@ var targets: [Target] = [
9876
"TSCExtensions",
9977
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols"),
10078
],
101-
swiftSettings: globalSwiftSettings
10279
),
10380

10481
.target(
@@ -124,7 +101,6 @@ var targets: [Target] = [
124101
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
125102
] + swiftSyntaxDependencies(["SwiftSyntax"]),
126103
exclude: ["CMakeLists.txt"],
127-
swiftSettings: globalSwiftSettings
128104
),
129105

130106
// MARK: CompletionScoring
@@ -133,26 +109,22 @@ var targets: [Target] = [
133109
name: "CompletionScoring",
134110
dependencies: ["CCompletionScoring"],
135111
exclude: ["CMakeLists.txt"],
136-
swiftSettings: globalSwiftSettings
137112
),
138113

139114
.target(
140115
name: "CompletionScoringForPlugin",
141116
dependencies: ["CCompletionScoring"],
142117
exclude: ["CMakeLists.txt"],
143-
swiftSettings: globalSwiftSettings
144118
),
145119

146120
.testTarget(
147121
name: "CompletionScoringTests",
148122
dependencies: ["CompletionScoring", "CompletionScoringTestSupport", "SwiftExtensions"],
149-
swiftSettings: globalSwiftSettings
150123
),
151124

152125
.testTarget(
153126
name: "CompletionScoringPerfTests",
154127
dependencies: ["CompletionScoring", "CompletionScoringTestSupport", "SwiftExtensions"],
155-
swiftSettings: globalSwiftSettings
156128
),
157129

158130
// MARK: CompletionScoringTestSupport
@@ -165,7 +137,6 @@ var targets: [Target] = [
165137
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
166138
],
167139
resources: [.copy("INPUTS")],
168-
swiftSettings: globalSwiftSettings
169140
),
170141

171142
// MARK: CSKTestSupport
@@ -204,7 +175,6 @@ var targets: [Target] = [
204175
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
205176
] + swiftSyntaxDependencies(["SwiftIDEUtils", "SwiftSyntax", "SwiftParser"]),
206177
exclude: ["CMakeLists.txt"],
207-
swiftSettings: globalSwiftSettings
208178
),
209179

210180
.testTarget(
@@ -218,7 +188,6 @@ var targets: [Target] = [
218188
.product(name: "SKLogging", package: "swift-tools-protocols"),
219189
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
220190
],
221-
swiftSettings: globalSwiftSettings
222191
),
223192

224193
// MARK: DocumentationLanguageService
@@ -240,7 +209,6 @@ var targets: [Target] = [
240209
.product(name: "SymbolKit", package: "swift-docc-symbolkit"),
241210
],
242211
exclude: [],
243-
swiftSettings: globalSwiftSettings
244212
),
245213

246214
// MARK: InProcessClient
@@ -261,7 +229,6 @@ var targets: [Target] = [
261229
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
262230
],
263231
exclude: ["CMakeLists.txt"],
264-
swiftSettings: globalSwiftSettings
265232
),
266233

267234
// MARK: LanguageServerProtocolExtensions
@@ -278,7 +245,6 @@ var targets: [Target] = [
278245
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
279246
],
280247
exclude: ["CMakeLists.txt"],
281-
swiftSettings: globalSwiftSettings
282248
),
283249

284250
// MARK: SemanticIndex
@@ -298,7 +264,6 @@ var targets: [Target] = [
298264
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
299265
],
300266
exclude: ["CMakeLists.txt"],
301-
swiftSettings: globalSwiftSettings
302267
),
303268

304269
.testTarget(
@@ -309,7 +274,6 @@ var targets: [Target] = [
309274
.product(name: "SKLogging", package: "swift-tools-protocols"),
310275
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
311276
],
312-
swiftSettings: globalSwiftSettings
313277
),
314278

315279
// MARK: SKOptions
@@ -323,7 +287,6 @@ var targets: [Target] = [
323287
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
324288
],
325289
exclude: ["CMakeLists.txt"],
326-
swiftSettings: globalSwiftSettings
327290
),
328291

329292
// MARK: SKUtilities
@@ -335,7 +298,6 @@ var targets: [Target] = [
335298
.product(name: "SKLogging", package: "swift-tools-protocols"),
336299
],
337300
exclude: ["CMakeLists.txt"],
338-
swiftSettings: globalSwiftSettings
339301
),
340302

341303
.target(
@@ -345,7 +307,7 @@ var targets: [Target] = [
345307
.product(name: "_SKLoggingForPlugin", package: "swift-tools-protocols"),
346308
],
347309
exclude: ["CMakeLists.txt"],
348-
swiftSettings: globalSwiftSettings + [
310+
swiftSettings: [
349311
.unsafeFlags([
350312
"-module-alias", "SKLogging=_SKLoggingForPlugin",
351313
"-module-alias", "SwiftExtensions=SwiftExtensionsForPlugin",
@@ -360,7 +322,6 @@ var targets: [Target] = [
360322
"SKUtilities",
361323
"SKTestSupport",
362324
],
363-
swiftSettings: globalSwiftSettings
364325
),
365326

366327
// MARK: SKTestSupport
@@ -388,7 +349,6 @@ var targets: [Target] = [
388349
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
389350
],
390351
resources: [.copy("INPUTS")],
391-
swiftSettings: globalSwiftSettings
392352
),
393353

394354
// MARK: SourceKitD
@@ -402,7 +362,6 @@ var targets: [Target] = [
402362
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
403363
],
404364
exclude: ["CMakeLists.txt", "sourcekitd_uids.swift.gyb"],
405-
swiftSettings: globalSwiftSettings
406365
),
407366

408367
.target(
@@ -414,7 +373,7 @@ var targets: [Target] = [
414373
.product(name: "_ToolsProtocolsSwiftExtensionsForPlugin", package: "swift-tools-protocols"),
415374
],
416375
exclude: ["CMakeLists.txt", "sourcekitd_uids.swift.gyb"],
417-
swiftSettings: globalSwiftSettings + [
376+
swiftSettings: [
418377
.unsafeFlags([
419378
"-module-alias", "SKLogging=_SKLoggingForPlugin",
420379
"-module-alias", "SwiftExtensions=SwiftExtensionsForPlugin",
@@ -433,7 +392,6 @@ var targets: [Target] = [
433392
"ToolchainRegistry",
434393
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
435394
],
436-
swiftSettings: globalSwiftSettings
437395
),
438396

439397
// MARK: SourceKitLSP
@@ -459,7 +417,6 @@ var targets: [Target] = [
459417
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
460418
] + swiftSyntaxDependencies(["SwiftSyntax"]),
461419
exclude: ["CMakeLists.txt"],
462-
swiftSettings: globalSwiftSettings
463420
),
464421

465422
.testTarget(
@@ -487,7 +444,6 @@ var targets: [Target] = [
487444
+ swiftSyntaxDependencies([
488445
"SwiftIfConfig", "SwiftParser", "SwiftSyntax", "SwiftCompilerPlugin", "SwiftSyntaxMacros",
489446
]),
490-
swiftSettings: globalSwiftSettings
491447
),
492448

493449
// MARK: SwiftExtensions
@@ -498,7 +454,6 @@ var targets: [Target] = [
498454
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols")
499455
],
500456
exclude: ["CMakeLists.txt"],
501-
swiftSettings: globalSwiftSettings
502457
),
503458

504459
.target(
@@ -507,7 +462,7 @@ var targets: [Target] = [
507462
.product(name: "_ToolsProtocolsSwiftExtensionsForPlugin", package: "swift-tools-protocols")
508463
],
509464
exclude: ["CMakeLists.txt"],
510-
swiftSettings: globalSwiftSettings + [
465+
swiftSettings: [
511466
.unsafeFlags([
512467
"-module-alias", "ToolsProtocolsSwiftExtensions=_ToolsProtocolsSwiftExtensionsForPlugin",
513468
])
@@ -522,7 +477,6 @@ var targets: [Target] = [
522477
.product(name: "SKLogging", package: "swift-tools-protocols"),
523478
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
524479
],
525-
swiftSettings: globalSwiftSettings
526480
),
527481

528482
// MARK: SwiftLanguageService
@@ -561,7 +515,6 @@ var targets: [Target] = [
561515
"SwiftSyntaxBuilder",
562516
]),
563517
exclude: ["CMakeLists.txt"],
564-
swiftSettings: globalSwiftSettings
565518
),
566519

567520
// MARK: SwiftSourceKitClientPlugin
@@ -575,7 +528,7 @@ var targets: [Target] = [
575528
"SwiftSourceKitPluginCommon",
576529
],
577530
exclude: ["CMakeLists.txt"],
578-
swiftSettings: globalSwiftSettings + [
531+
swiftSettings: [
579532
.unsafeFlags([
580533
"-module-alias", "SourceKitD=SourceKitDForPlugin",
581534
"-module-alias", "SwiftExtensions=SwiftExtensionsForPlugin",
@@ -596,7 +549,7 @@ var targets: [Target] = [
596549
.product(name: "_SKLoggingForPlugin", package: "swift-tools-protocols"),
597550
],
598551
exclude: ["CMakeLists.txt"],
599-
swiftSettings: globalSwiftSettings + [
552+
swiftSettings: [
600553
.unsafeFlags([
601554
"-module-alias", "SourceKitD=SourceKitDForPlugin",
602555
"-module-alias", "SwiftExtensions=SwiftExtensionsForPlugin",
@@ -621,7 +574,7 @@ var targets: [Target] = [
621574
.product(name: "_ToolsProtocolsSwiftExtensionsForPlugin", package: "swift-tools-protocols"),
622575
],
623576
exclude: ["CMakeLists.txt"],
624-
swiftSettings: globalSwiftSettings + [
577+
swiftSettings: [
625578
.unsafeFlags([
626579
"-module-alias", "CompletionScoring=CompletionScoringForPlugin",
627580
"-module-alias", "SKUtilities=SKUtilitiesForPlugin",
@@ -646,7 +599,6 @@ var targets: [Target] = [
646599
"ToolchainRegistry",
647600
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols"),
648601
],
649-
swiftSettings: globalSwiftSettings
650602
),
651603

652604
// MARK: ToolchainRegistry
@@ -660,7 +612,6 @@ var targets: [Target] = [
660612
.product(name: "SKLogging", package: "swift-tools-protocols"),
661613
],
662614
exclude: ["CMakeLists.txt"],
663-
swiftSettings: globalSwiftSettings
664615
),
665616

666617
.testTarget(
@@ -669,7 +620,6 @@ var targets: [Target] = [
669620
"SKTestSupport",
670621
"ToolchainRegistry",
671622
],
672-
swiftSettings: globalSwiftSettings
673623
),
674624

675625
// MARK: TSCExtensions
@@ -683,7 +633,6 @@ var targets: [Target] = [
683633
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
684634
],
685635
exclude: ["CMakeLists.txt"],
686-
swiftSettings: globalSwiftSettings
687636
),
688637

689638
.testTarget(
@@ -694,10 +643,39 @@ var targets: [Target] = [
694643
"TSCExtensions",
695644
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
696645
],
697-
swiftSettings: globalSwiftSettings
698646
),
699647
]
700648

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+
701679
if buildOnlyTests {
702680
products = []
703681
targets = targets.compactMap { target in

0 commit comments

Comments
 (0)