66import PackageDescription
77import class Foundation. ProcessInfo
88
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+
934let package = Package (
1035 name: " llbuild " ,
1136 platforms: [
@@ -22,10 +47,6 @@ let package = Package(
2247 . library(
2348 name: " llbuildSwift " ,
2449 targets: [ " llbuildSwift " ] ) ,
25- . library(
26- name: " llbuildSwiftDynamic " ,
27- type: . dynamic,
28- targets: [ " llbuildSwift " ] ) ,
2950 . library(
3051 name: " llbuildAnalysis " ,
3152 targets: [ " llbuildAnalysis " ] ) ,
@@ -83,12 +104,10 @@ let package = Package(
83104 name: " llbuildCore " ,
84105 dependencies: [
85106 " llbuildBasic " ,
86- . product( name: " SwiftToolchainCSQLite " , package : " swift-toolchain-sqlite " , condition: . when ( platforms : [ . windows ] ) ) ,
107+ . product( name: " SwiftToolchainCSQLite " , package : " swift-toolchain-sqlite " , condition: embeddedSqliteCondition ) ,
87108 ] ,
88109 path: " lib/Core " ,
89- linkerSettings: [
90- . linkedLibrary( " sqlite3 " , . when( platforms: [ . macOS, . iOS, . tvOS, . watchOS, . visionOS, . macCatalyst, . linux, . android] ) )
91- ]
110+ linkerSettings: externalSqliteLibraries
92111 ) ,
93112 . target(
94113 name: " llbuildBuildSystem " ,
@@ -129,15 +148,20 @@ let package = Package(
129148 . linkedLibrary( " pthread " , . when( platforms: [ . linux] ) ) ] ) ,
130149 . target(
131150 name: " llbuildCoreTests " ,
132- dependencies: [ " llbuildCore " , " gmocklib " ] ,
151+ dependencies: [
152+ " llbuildCore " ,
153+ " gmocklib " ,
154+ . product( name: " SwiftToolchainCSQLite " , package : " swift-toolchain-sqlite " , condition: embeddedSqliteCondition) ,
155+ ] ,
133156 path: " unittests/Core " ,
134157 cxxSettings: [
135158 . headerSearchPath( " ../../utils/unittest/googlemock/include " ) ,
136159 . headerSearchPath( " ../../utils/unittest/googletest/include " ) ,
137160 ] ,
138161 linkerSettings: [
139162 . linkedLibrary( " dl " , . when( platforms: [ . linux] ) ) ,
140- . linkedLibrary( " pthread " , . when( platforms: [ . linux] ) ) ] ) ,
163+ . linkedLibrary( " pthread " , . when( platforms: [ . linux] ) ) ,
164+ ] + externalSqliteLibraries) ,
141165 . target(
142166 name: " llbuildBuildSystemTests " ,
143167 dependencies: [ " llbuildBuildSystem " , " gmocklib " ] ,
@@ -231,12 +255,21 @@ let package = Package(
231255 path: " lib/llvm/Support " ,
232256 linkerSettings: [
233257 . linkedLibrary( " m " , . when( platforms: [ . linux] ) ) ,
234- . linkedLibrary ( " ncurses " , . when ( platforms : [ . linux , . macOS , . android ] ) ) ]
258+ ] + terminfoLibraries
235259 ) ,
236260 ] ,
237261 cxxLanguageStandard: . cxx14
238262)
239263
264+ if !isStaticBuild {
265+ package . products += [
266+ . library(
267+ name: " llbuildSwiftDynamic " ,
268+ type: . dynamic,
269+ targets: [ " llbuildSwift " ] ) ,
270+ ]
271+ }
272+
240273if ProcessInfo . processInfo. environment [ " SWIFTCI_USE_LOCAL_DEPS " ] == nil {
241274 package . dependencies += [
242275 . 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 {
247280 ]
248281}
249282
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 " ,
257286
258- " llvmDemangle " ,
259- " llvmSupport " ,
287+ " llvmDemangle " ,
288+ " llvmSupport " ,
260289
261- " llbuild " ,
262- " llbuildBasic " ,
263- " llbuildBuildSystem " ,
264- " llbuildCommands " ,
265- " llbuildNinja " ,
290+ " llbuild " ,
291+ " llbuildBasic " ,
292+ " llbuildBuildSystem " ,
293+ " llbuildCommands " ,
294+ " llbuildNinja " ,
266295
267- " llbuildBasicTests " ,
268- " llbuildBuildSystemTests " ,
269- " llbuildCoreTests " ,
270- " llbuildNinjaTests " ,
296+ " llbuildBasicTests " ,
297+ " llbuildBuildSystemTests " ,
298+ " llbuildCoreTests " ,
299+ " llbuildNinjaTests " ,
271300
272- " swift-build-tool " ,
273- ]
301+ " swift-build-tool " ,
302+ ]
274303
304+ if !useTerminfo {
275305 package . targets. filter ( { llvmTargets. contains ( $0. name) } ) . forEach { target in
276306 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 " ) ,
280308 ]
281309 }
282310}
283311
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+
284322package . targets. first { $0. name == " llbuildBasic " } ? . linkerSettings = [
285323 . linkedLibrary( " ShLwApi " , . when( platforms: [ . windows] ) )
286324]
0 commit comments