6
6
import PackageDescription
7
7
import class Foundation. ProcessInfo
8
8
9
+ let isStaticBuild = ProcessInfo . processInfo. environment [ " LLBUILD_STATIC_LINK " ] != nil
10
+ let useEmbeddedSqlite = isStaticBuild || ProcessInfo . processInfo. environment [ " LLBUILD_USE_EMBEDDED_SQLITE " ] != nil
11
+ let useTerminfo = !isStaticBuild && ProcessInfo . processInfo. environment [ " LLBUILD_NO_TERMINFO " ] == nil
12
+
13
+ let embeddedSqliteCondition : TargetDependencyCondition ? = {
14
+ if useEmbeddedSqlite {
15
+ return nil
16
+ }
17
+ return . when( platforms: [ . windows] )
18
+ } ( )
19
+
20
+ let externalSqliteLibraries : [ LinkerSetting ] = {
21
+ if useEmbeddedSqlite {
22
+ return [ ]
23
+ }
24
+ return [ . linkedLibrary( " sqlite3 " , . when( platforms: [ . macOS, . iOS, . tvOS, . watchOS, . visionOS, . macCatalyst, . linux, . android] ) ) ]
25
+ } ( )
26
+
27
+ let terminfoLibraries : [ LinkerSetting ] = {
28
+ if !useTerminfo {
29
+ return [ ]
30
+ }
31
+ return [ . linkedLibrary( " ncurses " , . when( platforms: [ . linux, . macOS, . android] ) ) ]
32
+ } ( )
33
+
9
34
let package = Package (
10
35
name: " llbuild " ,
11
36
platforms: [
@@ -22,10 +47,6 @@ let package = Package(
22
47
. library(
23
48
name: " llbuildSwift " ,
24
49
targets: [ " llbuildSwift " ] ) ,
25
- . library(
26
- name: " llbuildSwiftDynamic " ,
27
- type: . dynamic,
28
- targets: [ " llbuildSwift " ] ) ,
29
50
. library(
30
51
name: " llbuildAnalysis " ,
31
52
targets: [ " llbuildAnalysis " ] ) ,
@@ -83,12 +104,10 @@ let package = Package(
83
104
name: " llbuildCore " ,
84
105
dependencies: [
85
106
" llbuildBasic " ,
86
- . product( name: " SwiftToolchainCSQLite " , package : " swift-toolchain-sqlite " , condition: . when ( platforms : [ . windows ] ) ) ,
107
+ . product( name: " SwiftToolchainCSQLite " , package : " swift-toolchain-sqlite " , condition: embeddedSqliteCondition ) ,
87
108
] ,
88
109
path: " lib/Core " ,
89
- linkerSettings: [
90
- . linkedLibrary( " sqlite3 " , . when( platforms: [ . macOS, . iOS, . tvOS, . watchOS, . visionOS, . macCatalyst, . linux, . android] ) )
91
- ]
110
+ linkerSettings: externalSqliteLibraries
92
111
) ,
93
112
. target(
94
113
name: " llbuildBuildSystem " ,
@@ -129,15 +148,20 @@ let package = Package(
129
148
. linkedLibrary( " pthread " , . when( platforms: [ . linux] ) ) ] ) ,
130
149
. target(
131
150
name: " llbuildCoreTests " ,
132
- dependencies: [ " llbuildCore " , " gmocklib " ] ,
151
+ dependencies: [
152
+ " llbuildCore " ,
153
+ " gmocklib " ,
154
+ . product( name: " SwiftToolchainCSQLite " , package : " swift-toolchain-sqlite " , condition: embeddedSqliteCondition) ,
155
+ ] ,
133
156
path: " unittests/Core " ,
134
157
cxxSettings: [
135
158
. headerSearchPath( " ../../utils/unittest/googlemock/include " ) ,
136
159
. headerSearchPath( " ../../utils/unittest/googletest/include " ) ,
137
160
] ,
138
161
linkerSettings: [
139
162
. linkedLibrary( " dl " , . when( platforms: [ . linux] ) ) ,
140
- . linkedLibrary( " pthread " , . when( platforms: [ . linux] ) ) ] ) ,
163
+ . linkedLibrary( " pthread " , . when( platforms: [ . linux] ) ) ,
164
+ ] + externalSqliteLibraries) ,
141
165
. target(
142
166
name: " llbuildBuildSystemTests " ,
143
167
dependencies: [ " llbuildBuildSystem " , " gmocklib " ] ,
@@ -231,12 +255,21 @@ let package = Package(
231
255
path: " lib/llvm/Support " ,
232
256
linkerSettings: [
233
257
. linkedLibrary( " m " , . when( platforms: [ . linux] ) ) ,
234
- . linkedLibrary ( " ncurses " , . when ( platforms : [ . linux , . macOS , . android ] ) ) ]
258
+ ] + terminfoLibraries
235
259
) ,
236
260
] ,
237
261
cxxLanguageStandard: . cxx14
238
262
)
239
263
264
+ if !isStaticBuild {
265
+ package . products += [
266
+ . library(
267
+ name: " llbuildSwiftDynamic " ,
268
+ type: . dynamic,
269
+ targets: [ " llbuildSwift " ] ) ,
270
+ ]
271
+ }
272
+
240
273
if ProcessInfo . processInfo. environment [ " SWIFTCI_USE_LOCAL_DEPS " ] == nil {
241
274
package . dependencies += [
242
275
. package ( url: " https://github.com/swiftlang/swift-toolchain-sqlite " , from: " 1.0.0 " ) ,
@@ -247,40 +280,45 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
247
280
]
248
281
}
249
282
250
- // FIXME: Conditionalize these flags since SwiftPM 5.3 and earlier will crash for platforms they don't know about.
251
- #if os(Windows)
252
-
253
- do {
254
- let llvmTargets : Set < String > = [
255
- " libllbuild " ,
256
- " llbuildCore " ,
283
+ let llvmTargets : Set < String > = [
284
+ " libllbuild " ,
285
+ " llbuildCore " ,
257
286
258
- " llvmDemangle " ,
259
- " llvmSupport " ,
287
+ " llvmDemangle " ,
288
+ " llvmSupport " ,
260
289
261
- " llbuild " ,
262
- " llbuildBasic " ,
263
- " llbuildBuildSystem " ,
264
- " llbuildCommands " ,
265
- " llbuildNinja " ,
290
+ " llbuild " ,
291
+ " llbuildBasic " ,
292
+ " llbuildBuildSystem " ,
293
+ " llbuildCommands " ,
294
+ " llbuildNinja " ,
266
295
267
- " llbuildBasicTests " ,
268
- " llbuildBuildSystemTests " ,
269
- " llbuildCoreTests " ,
270
- " llbuildNinjaTests " ,
296
+ " llbuildBasicTests " ,
297
+ " llbuildBuildSystemTests " ,
298
+ " llbuildCoreTests " ,
299
+ " llbuildNinjaTests " ,
271
300
272
- " swift-build-tool " ,
273
- ]
301
+ " swift-build-tool " ,
302
+ ]
274
303
304
+ if !useTerminfo {
275
305
package . targets. filter ( { llvmTargets. contains ( $0. name) } ) . forEach { target in
276
306
target. cxxSettings = ( target. cxxSettings ?? [ ] ) + [
277
- . define( " LLVM_ON_WIN32 " , . when( platforms: [ . windows] ) ) ,
278
- . define( " _CRT_SECURE_NO_WARNINGS " , . when( platforms: [ . windows] ) ) ,
279
- . define( " _CRT_NONSTDC_NO_WARNINGS " , . when( platforms: [ . windows] ) ) ,
307
+ . define( " LLBUILD_NO_TERMINFO " ) ,
280
308
]
281
309
}
282
310
}
283
311
312
+ // FIXME: Conditionalize these flags since SwiftPM 5.3 and earlier will crash for platforms they don't know about.
313
+ #if os(Windows)
314
+ package . targets. filter ( { llvmTargets. contains ( $0. name) } ) . forEach { target in
315
+ target. cxxSettings = ( target. cxxSettings ?? [ ] ) + [
316
+ . define( " LLVM_ON_WIN32 " , . when( platforms: [ . windows] ) ) ,
317
+ . define( " _CRT_SECURE_NO_WARNINGS " , . when( platforms: [ . windows] ) ) ,
318
+ . define( " _CRT_NONSTDC_NO_WARNINGS " , . when( platforms: [ . windows] ) ) ,
319
+ ]
320
+ }
321
+
284
322
package . targets. first { $0. name == " llbuildBasic " } ? . linkerSettings = [
285
323
. linkedLibrary( " ShLwApi " , . when( platforms: [ . windows] ) )
286
324
]
0 commit comments