@@ -42,21 +42,21 @@ var targets: [Target] = [
4242 . target(
4343 name: " SwiftFormat " ,
4444 dependencies: [
45- . product( name: " Markdown " , package : " swift-markdown " ) ,
46- . product( name: " SwiftSyntax " , package : " swift-syntax " ) ,
47- . product( name: " SwiftSyntaxBuilder " , package : " swift-syntax " ) ,
48- . product( name: " SwiftOperators " , package : " swift-syntax " ) ,
49- . product( name: " SwiftParser " , package : " swift-syntax " ) ,
50- . product( name: " SwiftParserDiagnostics " , package : " swift-syntax " ) ,
51- ] ,
45+ . product( name: " Markdown " , package : " swift-markdown " )
46+ ]
47+ + swiftSyntaxDependencies( [
48+ " SwiftOperators " , " SwiftParser " , " SwiftParserDiagnostics " , " SwiftSyntax " , " SwiftSyntaxBuilder " ,
49+ ] ) ,
5250 exclude: [ " CMakeLists.txt " ]
5351 ) ,
5452 . target(
5553 name: " _SwiftFormatTestSupport " ,
5654 dependencies: [
57- " SwiftFormat " ,
58- . product( name: " SwiftOperators " , package : " swift-syntax " ) ,
55+ " SwiftFormat "
5956 ]
57+ + swiftSyntaxDependencies( [
58+ " SwiftOperators " , " SwiftParser " , " SwiftParserDiagnostics " , " SwiftSyntax " , " SwiftSyntaxBuilder " ,
59+ ] )
6060 ) ,
6161 . plugin(
6262 name: " Format Source Code " ,
@@ -98,7 +98,7 @@ var targets: [Target] = [
9898 . product( name: " ArgumentParser " , package : " swift-argument-parser " ) ,
9999 . product( name: " SwiftSyntax " , package : " swift-syntax " ) ,
100100 . product( name: " SwiftParser " , package : " swift-syntax " ) ,
101- ] ,
101+ ] + swiftSyntaxDependencies ( [ " SwiftParser " , " SwiftSyntax " ] ) ,
102102 exclude: [ " CMakeLists.txt " ] ,
103103 linkerSettings: swiftformatLinkSettings
104104 ) ,
@@ -110,7 +110,7 @@ var targets: [Target] = [
110110 " _SwiftFormatTestSupport " ,
111111 . product( name: " SwiftSyntax " , package : " swift-syntax " ) ,
112112 . product( name: " SwiftParser " , package : " swift-syntax " ) ,
113- ]
113+ ] + swiftSyntaxDependencies ( [ " SwiftParser " , " SwiftSyntax " ] )
114114 ) ,
115115 . testTarget(
116116 name: " SwiftFormatTests " ,
@@ -150,9 +150,16 @@ let package = Package(
150150 ] ,
151151 products: products,
152152 dependencies: dependencies,
153- targets: targets
154153)
155154
155+ func swiftSyntaxDependencies( _ names: [ String ] ) -> [ Target . Dependency ] {
156+ if buildDynamicSwiftSyntaxLibrary {
157+ return [ . product( name: " _SwiftSyntaxDynamic " , package : " swift-syntax " ) ]
158+ } else {
159+ return names. map { . product( name: $0, package : " swift-syntax " ) }
160+ }
161+ }
162+
156163// MARK: - Parse build arguments
157164
158165func hasEnvironmentVariable( _ name: String ) -> Bool {
@@ -174,6 +181,15 @@ var useLocalDependencies: Bool { hasEnvironmentVariable("SWIFTCI_USE_LOCAL_DEPS"
174181/// the `swift test` invocation so that all pre-built modules can be found.
175182var buildOnlyTests : Bool { hasEnvironmentVariable ( " SWIFTFORMAT_BUILD_ONLY_TESTS " ) }
176183
184+ /// Whether swift-syntax is being built as a single dynamic library instead of as a separate library per module.
185+ ///
186+ /// This means that the swift-syntax symbols don't need to be statically linked, which alles us to stay below the
187+ /// maximum number of exported symbols on Windows, in turn allowing us to build sourcekit-lsp using SwiftPM on Windows
188+ /// and run its tests.
189+ var buildDynamicSwiftSyntaxLibrary : Bool {
190+ hasEnvironmentVariable ( " SWIFTSYNTAX_BUILD_DYNAMIC_LIBRARY " )
191+ }
192+
177193// MARK: - Dependencies
178194
179195var dependencies : [ Package . Dependency ] {
0 commit comments