Skip to content

Commit 7737a76

Browse files
committed
Expose a low-level BSP interface wrapping SWBBuildServiceSession
SWBBuildServer implements BSP message handling and is intended to back a higher level BSP which manages the project model and generates PIF and a build request (SwiftPM). As part of this change, many of the core BSP types are vendored into the new SWBBuildServerProtocol target from SourceKitLSP with minor modifications.
1 parent 3b0c0b1 commit 7737a76

File tree

8 files changed

+1053
-5
lines changed

8 files changed

+1053
-5
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ add_compile_definitions(USE_STATIC_PLUGIN_INITIALIZATION)
8181
find_package(ArgumentParser)
8282
find_package(LLBuild)
8383
find_package(SwiftDriver)
84+
find_package(SwiftToolsProtocols)
8485
find_package(SwiftSystem)
8586
find_package(TSC)
8687
# NOTE: these two are required for LLBuild dependencies

Package.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,16 @@ let package = Package(
106106
// Libraries
107107
.target(
108108
name: "SwiftBuild",
109-
dependencies: ["SWBCSupport", "SWBCore", "SWBProtocol", "SWBUtil", "SWBProjectModel"],
109+
dependencies: [
110+
"SWBCSupport",
111+
"SWBCore",
112+
"SWBProtocol",
113+
"SWBUtil",
114+
"SWBProjectModel",
115+
.product(name: "BuildServerProtocol", package: "swift-tools-protocols", condition: .when(platforms: [.macOS, .linux, .windows, .android, .openbsd, .custom("freebsd")])),
116+
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols", condition: .when(platforms: [.macOS, .linux, .windows, .android, .openbsd, .custom("freebsd")])),
117+
.product(name: "LanguageServerProtocolTransport", package: "swift-tools-protocols", condition: .when(platforms: [.macOS, .linux, .windows, .android, .openbsd, .custom("freebsd")]))
118+
],
110119
exclude: ["CMakeLists.txt"],
111120
swiftSettings: swiftSettings(languageMode: .v5)),
112121
.target(
@@ -465,6 +474,7 @@ if useLocalDependencies {
465474
.package(path: "../swift-driver"),
466475
.package(path: "../swift-system"),
467476
.package(path: "../swift-argument-parser"),
477+
.package(path: "../swift-tools-protocols"),
468478
]
469479
if !useLLBuildFramework {
470480
package.dependencies += [.package(path: "../llbuild"),]
@@ -474,6 +484,7 @@ if useLocalDependencies {
474484
.package(url: "https://github.com/swiftlang/swift-driver.git", branch: "main"),
475485
.package(url: "https://github.com/apple/swift-system.git", .upToNextMajor(from: "1.5.0")),
476486
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.0.3"),
487+
.package(url: "https://github.com/swiftlang/swift-tools-protocols.git", .upToNextMinor(from: "0.0.9")),
477488
]
478489
if !useLLBuildFramework {
479490
package.dependencies += [.package(url: "https://github.com/swiftlang/swift-llbuild.git", branch: "main"),]

Plugins/cmake-smoke-test/cmake-smoke-test.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ struct CMakeSmokeTest: CommandPlugin {
5858
let swiftDriverURL = try findDependency("swift-driver", pluginContext: context)
5959
let swiftDriverBuildURL = context.pluginWorkDirectoryURL.appending(component: "swift-driver")
6060

61-
for url in [swiftToolsSupportCoreBuildURL, swiftSystemBuildURL, llbuildBuildURL, swiftArgumentParserBuildURL, swiftDriverBuildURL, swiftBuildBuildURL] {
61+
let swiftToolsProtocolsURL = try findDependency("swift-tools-protocols", pluginContext: context)
62+
let swiftToolsProtocolsBuildURL = context.pluginWorkDirectoryURL.appending(component: "swift-tools-protocols")
63+
64+
for url in [swiftToolsSupportCoreBuildURL, swiftSystemBuildURL, llbuildBuildURL, swiftArgumentParserBuildURL, swiftDriverBuildURL, swiftToolsProtocolsBuildURL, swiftBuildBuildURL] {
6265
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
6366
}
6467

@@ -75,7 +78,8 @@ struct CMakeSmokeTest: CommandPlugin {
7578
"-DLLBuild_DIR=\(llbuildBuildURL.appending(components: "cmake", "modules").filePath)",
7679
"-DTSC_DIR=\(swiftToolsSupportCoreBuildURL.appending(components: "cmake", "modules").filePath)",
7780
"-DSwiftDriver_DIR=\(swiftDriverBuildURL.appending(components: "cmake", "modules").filePath)",
78-
"-DSwiftSystem_DIR=\(swiftSystemBuildURL.appending(components: "cmake", "modules").filePath)"
81+
"-DSwiftSystem_DIR=\(swiftSystemBuildURL.appending(components: "cmake", "modules").filePath)",
82+
"-DSwiftToolsProtocols_DIR=\(swiftToolsProtocolsBuildURL.appending(components: "cmake", "modules").filePath)"
7983
]
8084

8185
let sharedCMakeArgs = [
@@ -112,6 +116,11 @@ struct CMakeSmokeTest: CommandPlugin {
112116
try await Process.checkNonZeroExit(url: ninjaURL, arguments: [], workingDirectory: swiftDriverBuildURL)
113117
Diagnostics.progress("Built swift-driver")
114118

119+
Diagnostics.progress("Building swift-tools-protocols")
120+
try await Process.checkNonZeroExit(url: cmakeURL, arguments: sharedCMakeArgs + [swiftToolsProtocolsURL.filePath], workingDirectory: swiftToolsProtocolsBuildURL)
121+
try await Process.checkNonZeroExit(url: ninjaURL, arguments: [], workingDirectory: swiftToolsProtocolsBuildURL)
122+
Diagnostics.progress("Built swift-tools-protocols")
123+
115124
Diagnostics.progress("Building swift-build in \(swiftBuildBuildURL)")
116125
try await Process.checkNonZeroExit(url: cmakeURL, arguments: sharedCMakeArgs + [swiftBuildURL.filePath], workingDirectory: swiftBuildBuildURL)
117126
try await Process.checkNonZeroExit(url: ninjaURL, arguments: [], workingDirectory: swiftBuildBuildURL)

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ public final class BuiltinMacros {
483483
public static let BUILD_DIR = BuiltinMacros.declarePathMacro("BUILD_DIR")
484484
public static let BUILD_LIBRARY_FOR_DISTRIBUTION = BuiltinMacros.declareBooleanMacro("BUILD_LIBRARY_FOR_DISTRIBUTION")
485485
public static let BUILD_PACKAGE_FOR_DISTRIBUTION = BuiltinMacros.declareBooleanMacro("BUILD_PACKAGE_FOR_DISTRIBUTION")
486+
public static let BUILD_SERVER_PROTOCOL_TARGET_TAGS = BuiltinMacros.declareBooleanMacro("BUILD_SERVER_PROTOCOL_TARGET_TAGS")
486487
public static let BUILD_VARIANTS = BuiltinMacros.declareStringListMacro("BUILD_VARIANTS")
487488
public static let BuiltBinaryPath = BuiltinMacros.declareStringMacro("BuiltBinaryPath")
488489
public static let BUNDLE_FORMAT = BuiltinMacros.declareStringMacro("BUNDLE_FORMAT")
@@ -1484,6 +1485,7 @@ public final class BuiltinMacros {
14841485
BUILD_DIR,
14851486
BUILD_LIBRARY_FOR_DISTRIBUTION,
14861487
BUILD_PACKAGE_FOR_DISTRIBUTION,
1488+
BUILD_SERVER_PROTOCOL_TARGET_TAGS,
14871489
BUILD_STYLE,
14881490
BUILD_VARIANTS,
14891491
BUILT_PRODUCTS_DIR,

Sources/SwiftBuild/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ add_library(SwiftBuild
3636
SWBBuildOperationBacktraceFrame.swift
3737
SWBBuildParameters.swift
3838
SWBBuildRequest.swift
39+
SWBBuildServer.swift
3940
SWBBuildService.swift
4041
SWBBuildServiceConnection.swift
4142
SWBBuildServiceConsole.swift
@@ -70,7 +71,12 @@ target_link_libraries(SwiftBuild PUBLIC
7071
SWBCore
7172
SWBProtocol
7273
SWBUtil
73-
SWBProjectModel)
74+
SWBProjectModel
75+
SwiftToolsProtocols::SKLogging
76+
SwiftToolsProtocols::ToolsProtocolsSwiftExtensions
77+
SwiftToolsProtocols::BuildServerProtocol
78+
SwiftToolsProtocols::LanguageServerProtocol
79+
SwiftToolsProtocols::LanguageServerProtocolTransport)
7480

7581
set_target_properties(SwiftBuild PROPERTIES
7682
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

0 commit comments

Comments
 (0)