forked from swiftlang/sourcekit-lsp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Package.swift
511 lines (448 loc) · 14.7 KB
/
Package.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
// swift-tools-version: 5.10
import Foundation
import PackageDescription
/// Swift settings that should be applied to every Swift target.
let globalSwiftSettings: [SwiftSetting] = [
.enableUpcomingFeature("InternalImportsByDefault")
]
let package = Package(
name: "SourceKitLSP",
platforms: [.macOS(.v13)],
products: [
.executable(name: "sourcekit-lsp", targets: ["sourcekit-lsp"]),
.library(name: "_SourceKitLSP", targets: ["SourceKitLSP"]),
.library(name: "LSPBindings", targets: ["LanguageServerProtocol", "LanguageServerProtocolJSONRPC"]),
],
dependencies: dependencies,
targets: [
// Formatting style:
// - One section for each target and its test target
// - Sections are sorted alphabetically
// - Dependencies are listed on separate lines
// - All array elements are sorted alphabetically
// MARK: sourcekit-lsp
.executableTarget(
name: "sourcekit-lsp",
dependencies: [
"BuildSystemIntegration",
"Diagnose",
"LanguageServerProtocol",
"LanguageServerProtocolJSONRPC",
"SKOptions",
"SKSupport",
"SourceKitLSP",
"ToolchainRegistry",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings,
linkerSettings: sourcekitLSPLinkSettings
),
// MARK: BuildServerProtocol
.target(
name: "BuildServerProtocol",
dependencies: [
"LanguageServerProtocol"
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
// MARK: BuildSystemIntegration
.target(
name: "BuildSystemIntegration",
dependencies: [
"BuildServerProtocol",
"LanguageServerProtocol",
"LanguageServerProtocolJSONRPC",
"SKLogging",
"SKOptions",
"SKSupport",
"SourceKitD",
"SwiftExtensions",
"ToolchainRegistry",
.product(name: "SwiftPM-auto", package: "swift-package-manager"),
.product(name: "SwiftPMDataModel-auto", package: "swift-package-manager"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
.testTarget(
name: "BuildSystemIntegrationTests",
dependencies: [
"BuildSystemIntegration",
"LanguageServerProtocol",
"SKOptions",
"SKTestSupport",
"SourceKitLSP",
"ToolchainRegistry",
],
swiftSettings: globalSwiftSettings
),
// MARK: CAtomics
.target(
name: "CAtomics",
dependencies: []
),
// MARK: CSKTestSupport
.target(
name: "CSKTestSupport",
dependencies: []
),
// MARK: Csourcekitd
.target(
name: "Csourcekitd",
dependencies: [],
exclude: ["CMakeLists.txt"]
),
// MARK: Diagnose
.target(
name: "Diagnose",
dependencies: [
"BuildSystemIntegration",
"InProcessClient",
"SKLogging",
"SKOptions",
"SKSupport",
"SourceKitD",
"SourceKitLSP",
"SwiftExtensions",
"ToolchainRegistry",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SwiftIDEUtils", package: "swift-syntax"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
.testTarget(
name: "DiagnoseTests",
dependencies: [
"BuildSystemIntegration",
"Diagnose",
"SKLogging",
"SKTestSupport",
"SourceKitD",
"ToolchainRegistry",
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
swiftSettings: globalSwiftSettings
),
// MARK: InProcessClient
.target(
name: "InProcessClient",
dependencies: [
"BuildSystemIntegration",
"LanguageServerProtocol",
"SKLogging",
"SKOptions",
"SourceKitLSP",
"ToolchainRegistry",
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
// MARK: LanguageServerProtocol
.target(
name: "LanguageServerProtocol",
dependencies: [],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
.testTarget(
name: "LanguageServerProtocolTests",
dependencies: [
"LanguageServerProtocol",
"SKTestSupport",
],
swiftSettings: globalSwiftSettings
),
// MARK: LanguageServerProtocolJSONRPC
.target(
name: "LanguageServerProtocolJSONRPC",
dependencies: [
"LanguageServerProtocol",
"SKLogging",
"SwiftExtensions",
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
.testTarget(
name: "LanguageServerProtocolJSONRPCTests",
dependencies: [
"LanguageServerProtocolJSONRPC",
"SKTestSupport",
],
swiftSettings: globalSwiftSettings
),
// MARK: SemanticIndex
.target(
name: "SemanticIndex",
dependencies: [
"BuildSystemIntegration",
"LanguageServerProtocol",
"SKLogging",
"SwiftExtensions",
"ToolchainRegistry",
.product(name: "IndexStoreDB", package: "indexstore-db"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
.testTarget(
name: "SemanticIndexTests",
dependencies: [
"SemanticIndex",
"SKLogging",
"SKTestSupport",
],
swiftSettings: globalSwiftSettings
),
// MARK: SKLogging
.target(
name: "SKLogging",
dependencies: [
"SwiftExtensions",
.product(name: "Crypto", package: "swift-crypto"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings + lspLoggingSwiftSettings
),
.testTarget(
name: "SKLoggingTests",
dependencies: [
"SKLogging",
"SKTestSupport",
],
swiftSettings: globalSwiftSettings
),
// MARK: SKOptions
.target(
name: "SKOptions",
dependencies: [
"LanguageServerProtocol",
"SKLogging",
"SKSupport",
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
// MARK: SKSupport
.target(
name: "SKSupport",
dependencies: [
"LanguageServerProtocol",
"LanguageServerProtocolJSONRPC",
"SKLogging",
"SourceKitD",
"SwiftExtensions",
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
.testTarget(
name: "SKSupportTests",
dependencies: [
"SKSupport",
"SKTestSupport",
"SwiftExtensions",
],
swiftSettings: globalSwiftSettings
),
// MARK: SKTestSupport
.target(
name: "SKTestSupport",
dependencies: [
"BuildSystemIntegration",
"CSKTestSupport",
"InProcessClient",
"LanguageServerProtocol",
"LanguageServerProtocolJSONRPC",
"SKLogging",
"SKOptions",
"SKSupport",
"SourceKitLSP",
"SwiftExtensions",
"ToolchainRegistry",
.product(name: "ISDBTestSupport", package: "indexstore-db"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
resources: [.copy("INPUTS")],
swiftSettings: globalSwiftSettings
),
// MARK: SourceKitD
.target(
name: "SourceKitD",
dependencies: [
"Csourcekitd",
"SKLogging",
"SwiftExtensions",
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt", "sourcekitd_uids.swift.gyb"],
swiftSettings: globalSwiftSettings
),
.testTarget(
name: "SourceKitDTests",
dependencies: [
"BuildSystemIntegration",
"SourceKitD",
"SKTestSupport",
"SwiftExtensions",
"ToolchainRegistry",
],
swiftSettings: globalSwiftSettings
),
// MARK: SourceKitLSP
.target(
name: "SourceKitLSP",
dependencies: [
"BuildServerProtocol",
"BuildSystemIntegration",
"LanguageServerProtocol",
"LanguageServerProtocolJSONRPC",
"SemanticIndex",
"SKLogging",
"SKOptions",
"SKSupport",
"SourceKitD",
"SwiftExtensions",
"ToolchainRegistry",
.product(name: "IndexStoreDB", package: "indexstore-db"),
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
.product(name: "SwiftIDEUtils", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftParserDiagnostics", package: "swift-syntax"),
.product(name: "SwiftRefactor", package: "swift-syntax"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
.product(name: "SwiftPM-auto", package: "swift-package-manager"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
.testTarget(
name: "SourceKitLSPTests",
dependencies: [
"BuildServerProtocol",
"BuildSystemIntegration",
"LanguageServerProtocol",
"SemanticIndex",
"SKLogging",
"SKOptions",
"SKSupport",
"SKTestSupport",
"SourceKitD",
"SourceKitLSP",
"ToolchainRegistry",
.product(name: "IndexStoreDB", package: "indexstore-db"),
.product(name: "ISDBTestSupport", package: "indexstore-db"),
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
// Depend on `SwiftCompilerPlugin` and `SwiftSyntaxMacros` so the modules are built before running tests and can
// be used by test cases that test macros (see `SwiftPMTestProject.macroPackageManifest`).
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
],
swiftSettings: globalSwiftSettings
),
// MARK: SwiftExtensions
.target(
name: "SwiftExtensions",
dependencies: ["CAtomics"],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
// MARK: ToolchainRegistry
.target(
name: "ToolchainRegistry",
dependencies: [
"SKLogging",
"SKSupport",
"SwiftExtensions",
.product(name: "SwiftPMDataModel-auto", package: "swift-package-manager"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
.testTarget(
name: "ToolchainRegistryTests",
dependencies: [
"SKTestSupport",
"ToolchainRegistry",
.product(name: "SwiftPMDataModel-auto", package: "swift-package-manager"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
swiftSettings: globalSwiftSettings
),
],
swiftLanguageVersions: [.v5, .version("6")]
)
// MARK: - Parse build arguments
func hasEnvironmentVariable(_ name: String) -> Bool {
return ProcessInfo.processInfo.environment[name] != nil
}
/// Use the `NonDarwinLogger` even if `os_log` can be imported.
///
/// This is useful when running tests using `swift test` because xctest will not display the output from `os_log` on the
/// command line.
var forceNonDarwinLogger: Bool { hasEnvironmentVariable("SOURCEKIT_LSP_FORCE_NON_DARWIN_LOGGER") }
// When building the toolchain on the CI, don't add the CI's runpath for the
// final build before installing.
var installAction: Bool { hasEnvironmentVariable("SOURCEKIT_LSP_CI_INSTALL") }
/// Assume that all the package dependencies are checked out next to sourcekit-lsp and use that instead of fetching a
/// remote dependency.
var useLocalDependencies: Bool { hasEnvironmentVariable("SWIFTCI_USE_LOCAL_DEPS") }
// MARK: - Dependencies
// When building with the swift build-script, use local dependencies whose contents are controlled
// by the external environment. This allows sourcekit-lsp to take advantage of the automation used
// for building the swift toolchain, such as `update-checkout`, or cross-repo PR tests.
var dependencies: [Package.Dependency] {
if useLocalDependencies {
return [
.package(path: "../indexstore-db"),
.package(name: "swift-package-manager", path: "../swiftpm"),
.package(path: "../swift-tools-support-core"),
.package(path: "../swift-argument-parser"),
.package(path: "../swift-syntax"),
.package(path: "../swift-crypto"),
]
} else {
let relatedDependenciesBranch = "main"
return [
.package(url: "https://github.com/swiftlang/indexstore-db.git", branch: relatedDependenciesBranch),
.package(url: "https://github.com/swiftlang/swift-package-manager.git", branch: relatedDependenciesBranch),
.package(url: "https://github.com/apple/swift-tools-support-core.git", branch: relatedDependenciesBranch),
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.4.0"),
.package(url: "https://github.com/swiftlang/swift-syntax.git", branch: relatedDependenciesBranch),
.package(url: "https://github.com/apple/swift-crypto.git", from: "3.0.0"),
// Not a build dependency. Used so the "Format Source Code" command plugin can be used to format sourcekit-lsp
.package(url: "https://github.com/swiftlang/swift-format.git", branch: relatedDependenciesBranch),
]
}
}
// MARK: - Compute custom build settings
var sourcekitLSPLinkSettings: [LinkerSetting] {
if installAction {
return [.unsafeFlags(["-no-toolchain-stdlib-rpath"], .when(platforms: [.linux, .android]))]
} else {
return []
}
}
var lspLoggingSwiftSettings: [SwiftSetting] {
if forceNonDarwinLogger {
return [.define("SOURCEKIT_LSP_FORCE_NON_DARWIN_LOGGER")]
} else {
return []
}
}