forked from swiftlang/sourcekit-lsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Package.swift
498 lines (439 loc) · 14.6 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
// swift-tools-version: 5.8
import Foundation
import PackageDescription
let strictConcurrencySettings: [SwiftSetting] = [
.enableUpcomingFeature("StrictConcurrency"),
.enableUpcomingFeature("RegionBasedIsolation"),
.enableUpcomingFeature("InferSendableFromCaptures"),
]
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: [
"Diagnose",
"LanguageServerProtocol",
"LanguageServerProtocolJSONRPC",
"SKCore",
"SKSupport",
"SourceKitLSP",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings,
linkerSettings: sourcekitLSPLinkSettings
),
// MARK: BuildServerProtocol
// Connection between build server and language server to provide build and index info
.target(
name: "BuildServerProtocol",
dependencies: [
"LanguageServerProtocol"
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
),
// MARK: CAtomics
.target(
name: "CAtomics",
dependencies: []
),
// MARK: CSKTestSupport
.target(
name: "CSKTestSupport",
dependencies: []
),
// MARK: Csourcekitd
// C modules wrapper for sourcekitd.
.target(
name: "Csourcekitd",
dependencies: [],
exclude: ["CMakeLists.txt"]
),
// MARK: Diagnose
.target(
name: "Diagnose",
dependencies: [
"InProcessClient",
"LSPLogging",
"SKCore",
"SKSupport",
"SourceKitD",
"SourceKitLSP",
"SwiftExtensions",
.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: strictConcurrencySettings
),
.testTarget(
name: "DiagnoseTests",
dependencies: [
"Diagnose",
"LSPLogging",
"LSPTestSupport",
"SourceKitD",
"SKCore",
"SKTestSupport",
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
swiftSettings: strictConcurrencySettings
),
// MARK: InProcessClient
.target(
name: "InProcessClient",
dependencies: [
"LanguageServerProtocol",
"LSPLogging",
"SKCore",
"SourceKitLSP",
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
),
// MARK: LanguageServerProtocol
// The core LSP types, suitable for any LSP implementation.
.target(
name: "LanguageServerProtocol",
dependencies: [],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
),
.testTarget(
name: "LanguageServerProtocolTests",
dependencies: [
"LanguageServerProtocol",
"LSPTestSupport",
],
swiftSettings: strictConcurrencySettings
),
// MARK: LanguageServerProtocolJSONRPC
// LSP connection using jsonrpc over pipes.
.target(
name: "LanguageServerProtocolJSONRPC",
dependencies: [
"LanguageServerProtocol",
"LSPLogging",
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
),
.testTarget(
name: "LanguageServerProtocolJSONRPCTests",
dependencies: [
"LanguageServerProtocolJSONRPC",
"LSPTestSupport",
],
swiftSettings: strictConcurrencySettings
),
// MARK: LSPLogging
// Logging support used in LSP modules.
.target(
name: "LSPLogging",
dependencies: [
"SwiftExtensions",
.product(name: "Crypto", package: "swift-crypto"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: lspLoggingSwiftSettings + strictConcurrencySettings
),
.testTarget(
name: "LSPLoggingTests",
dependencies: [
"LSPLogging",
"SKTestSupport",
],
swiftSettings: strictConcurrencySettings
),
// MARK: LSPTestSupport
.target(
name: "LSPTestSupport",
dependencies: [
"InProcessClient",
"LanguageServerProtocol",
"LanguageServerProtocolJSONRPC",
"SKSupport",
"SwiftExtensions",
],
swiftSettings: strictConcurrencySettings
),
// MARK: SemanticIndex
.target(
name: "SemanticIndex",
dependencies: [
"LanguageServerProtocol",
"LSPLogging",
"SKCore",
"SwiftExtensions",
.product(name: "IndexStoreDB", package: "indexstore-db"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
),
.testTarget(
name: "SemanticIndexTests",
dependencies: [
"SemanticIndex"
],
swiftSettings: strictConcurrencySettings
),
// MARK: SKCore
// Data structures and algorithms useful across the project, but not necessarily
// suitable for use in other packages.
.target(
name: "SKCore",
dependencies: [
"BuildServerProtocol",
"LanguageServerProtocol",
"LanguageServerProtocolJSONRPC",
"LSPLogging",
"SKSupport",
"SourceKitD",
"SwiftExtensions",
.product(name: "SwiftPMDataModel-auto", package: "swift-package-manager"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
),
.testTarget(
name: "SKCoreTests",
dependencies: [
"SKCore",
"SKTestSupport",
],
swiftSettings: strictConcurrencySettings
),
// MARK: SKSupport
// Data structures, algorithms and platform-abstraction code that might be generally useful to any Swift package.
// Similar in spirit to SwiftPM's Basic module.
.target(
name: "SKSupport",
dependencies: [
"CAtomics",
"LanguageServerProtocol",
"LSPLogging",
"SwiftExtensions",
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
),
.testTarget(
name: "SKSupportTests",
dependencies: [
"LSPTestSupport",
"SKSupport",
"SKTestSupport",
"SwiftExtensions",
],
swiftSettings: strictConcurrencySettings
),
// MARK: SKSwiftPMWorkspace
.target(
name: "SKSwiftPMWorkspace",
dependencies: [
"BuildServerProtocol",
"LanguageServerProtocol",
"LSPLogging",
"SKCore",
"SwiftExtensions",
.product(name: "SwiftPM-auto", package: "swift-package-manager"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
),
.testTarget(
name: "SKSwiftPMWorkspaceTests",
dependencies: [
"LSPTestSupport",
"LanguageServerProtocol",
"SKCore",
"SKSwiftPMWorkspace",
"SKTestSupport",
"SourceKitLSP",
.product(name: "SwiftPM-auto", package: "swift-package-manager"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
swiftSettings: strictConcurrencySettings
),
// MARK: SKTestSupport
.target(
name: "SKTestSupport",
dependencies: [
"CSKTestSupport",
"InProcessClient",
"LanguageServerProtocol",
"LSPTestSupport",
"LSPLogging",
"SKCore",
"SourceKitLSP",
"SwiftExtensions",
.product(name: "ISDBTestSupport", package: "indexstore-db"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
resources: [.copy("INPUTS")],
swiftSettings: strictConcurrencySettings
),
// MARK: SourceKitD
// Swift bindings for sourcekitd.
.target(
name: "SourceKitD",
dependencies: [
"Csourcekitd",
"LSPLogging",
"SKSupport",
"SwiftExtensions",
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt", "sourcekitd_uids.swift.gyb"],
swiftSettings: strictConcurrencySettings
),
.testTarget(
name: "SourceKitDTests",
dependencies: [
"SourceKitD",
"SKCore",
"SKTestSupport",
"SwiftExtensions",
],
swiftSettings: strictConcurrencySettings
),
// MARK: SourceKitLSP
.target(
name: "SourceKitLSP",
dependencies: [
"BuildServerProtocol",
"LanguageServerProtocol",
"LanguageServerProtocolJSONRPC",
"LSPLogging",
"SemanticIndex",
"SKCore",
"SKSupport",
"SKSwiftPMWorkspace",
"SourceKitD",
"SwiftExtensions",
.product(name: "IndexStoreDB", package: "indexstore-db"),
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
.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: strictConcurrencySettings
),
.testTarget(
name: "SourceKitLSPTests",
dependencies: [
"BuildServerProtocol",
"LSPLogging",
"LSPTestSupport",
"LanguageServerProtocol",
"SKCore",
"SKSupport",
"SKTestSupport",
"SourceKitD",
"SourceKitLSP",
.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: strictConcurrencySettings
),
// MARK: SwiftExtensions
.target(
name: "SwiftExtensions",
exclude: ["CMakeLists.txt"],
swiftSettings: strictConcurrencySettings
),
]
)
// 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("SOURCEKITLSP_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.2.2"),
.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("SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER")]
} else {
return []
}
}