15
15
import class Foundation. ProcessInfo
16
16
import PackageDescription
17
17
18
- // When building the toolchain on the CI for ELF platforms, remove the CI's
18
+ func defined( _ variable: String ) -> Bool {
19
+ ProcessInfo . processInfo. environment [ variable] != nil
20
+ }
21
+
22
+ var buildOnlyTests : Bool {
23
+ defined ( " SWIFTPM_BUILD_ONLY_TESTS " )
24
+ }
25
+
26
+ var useLocalDependencies : Bool {
27
+ defined ( " SWIFTCI_USE_LOCAL_DEPS " )
28
+ }
29
+
30
+ var useLLBuildFramework : Bool {
31
+ defined ( " SWIFTPM_LLBUILD_FWK " )
32
+ }
33
+
34
+ var useSwiftBuildFramework : Bool {
35
+ defined ( " SWIFTPM_SWBUILD_FRAMEWORK " )
36
+ }
37
+
38
+ @MainActor
39
+ func LLBuildFrameworkDependency< T> ( enabled: [ T ] = [ ] , disabled: [ T ] = [ ] ) -> [ T ] {
40
+ if useLLBuildFramework { return enabled }
41
+ return disabled
42
+ }
43
+
44
+ @MainActor
45
+ func SwiftBuildFrameworkDependency< T> ( enabled: [ T ] = [ ] , disabled: [ T ] = [ ] ) -> [ T ] {
46
+ if useSwiftBuildFramework { return enabled }
47
+ return disabled
48
+ }
49
+
50
+ var dependencies : [ Package . Dependency ] {
51
+ if buildOnlyTests { return [ ] }
52
+
53
+ if useLocalDependencies {
54
+ return [
55
+ . package ( path: " ../swift-argument-parser " ) ,
56
+ . package ( path: " ../swift-crypto " ) ,
57
+ . package ( path: " ../swift-syntax " ) ,
58
+ . package ( path: " ../swift-system " ) ,
59
+ . package ( path: " ../swift-collections " ) ,
60
+ . package ( path: " ../swift-certificates " ) ,
61
+ . package ( path: " ../swift-toolchain-sqlite " ) ,
62
+ ] + LLBuildFrameworkDependency( disabled: [
63
+ . package ( name: " swift-llbuild " , path: " ../llbuild " ) ,
64
+ ] ) + SwiftBuildFrameworkDependency( enabled: [
65
+ . package ( path: " ../swift-build " ) ,
66
+ ] , disabled: [
67
+ . package ( path: " ../swift-tools-support-core " ) ,
68
+ . package ( path: " ../swift-driver " ) ,
69
+ ] )
70
+ }
71
+
72
+ /// When not using local dependencies, the branch to use for llbuild and TSC
73
+ /// repositories.
74
+ let relatedDependenciesBranch = " main "
75
+
76
+ return [
77
+ // The 'swift-argument-parser' version declared here must match that
78
+ // used by 'swift-driver' and 'sourcekit-lsp'. Please coordinate
79
+ // dependency version changes here with those projects.
80
+ . package ( url: " https://github.com/apple/swift-argument-parser.git " , . upToNextMinor( from: " 1.5.1 " ) ) ,
81
+ . package ( url: " https://github.com/apple/swift-crypto.git " , . upToNextMinor( from: " 3.0.0 " ) ) ,
82
+ . package ( url: " https://github.com/swiftlang/swift-syntax.git " , branch: relatedDependenciesBranch) ,
83
+ . package ( url: " https://github.com/apple/swift-system.git " , from: " 1.1.1 " ) ,
84
+ . package ( url: " https://github.com/apple/swift-collections.git " , " 1.0.1 " ..< " 1.2.0 " ) ,
85
+ . package ( url: " https://github.com/apple/swift-certificates.git " , " 1.0.1 " ..< " 1.6.0 " ) ,
86
+ . package ( url: " https://github.com/swiftlang/swift-toolchain-sqlite.git " , from: " 1.0.0 " ) ,
87
+
88
+ // For use in previewing documentation
89
+ . package ( url: " https://github.com/swiftlang/swift-docc-plugin " , from: " 1.1.0 " ) ,
90
+ ] + LLBuildFrameworkDependency( disabled: [
91
+ . package ( url: " https://github.com/swiftlang/swift-llbuild.git " , branch: relatedDependenciesBranch) ,
92
+ ] ) + SwiftBuildFrameworkDependency( enabled: [
93
+ . package ( url: " https://github.com/swiftlang/swift-build.git " , branch: relatedDependenciesBranch) ,
94
+ ] , disabled: [
95
+ . package ( url: " https://github.com/swiftlang/swift-tools-support-core.git " , branch: relatedDependenciesBranch) ,
96
+ . package ( url: " https://github.com/swiftlang/swift-driver.git " , branch: relatedDependenciesBranch) ,
97
+ ] )
98
+ }
99
+
100
+
101
+ // When building the toolchain on the CI for ELF platforms, remove the CI's !=
102
+ // nil
19
103
// stdlib absolute runpath and add ELF's $ORIGIN relative paths before installing.
20
104
let swiftpmLinkSettings : [ LinkerSetting ]
21
105
let packageLibraryLinkSettings : [ LinkerSetting ]
@@ -101,39 +185,14 @@ if ProcessInfo.processInfo.environment["SWIFTCI_INSTALL_RPATH_OS"] == "android"
101
185
*/
102
186
let autoProducts = [ swiftPMProduct, swiftPMDataModelProduct]
103
187
104
- let shoudUseSwiftBuildFramework = ( ProcessInfo . processInfo. environment [ " SWIFTPM_SWBUILD_FRAMEWORK " ] != nil )
105
-
106
- let swiftDriverDeps : [ Target . Dependency ]
107
- let swiftTSCBasicsDeps : [ Target . Dependency ]
108
- let swiftToolsCoreSupportAutoDeps : [ Target . Dependency ]
109
- let swiftTSCTestSupportDeps : [ Target . Dependency ]
110
-
111
- if shoudUseSwiftBuildFramework {
112
- swiftDriverDeps = [ ]
113
- swiftTSCBasicsDeps = [ ]
114
- swiftToolsCoreSupportAutoDeps = [ ]
115
- swiftTSCTestSupportDeps = [ ]
116
- } else {
117
- swiftDriverDeps = [
118
- . product( name: " SwiftDriver " , package : " swift-driver " )
119
- ]
120
- swiftTSCBasicsDeps = [
121
- . product( name: " TSCBasic " , package : " swift-tools-support-core " ) ,
122
- ]
123
- swiftToolsCoreSupportAutoDeps = [
124
- . product( name: " SwiftToolsSupport-auto " , package : " swift-tools-support-core " )
125
- ]
126
- swiftTSCTestSupportDeps = [
127
- . product( name: " TSCTestSupport " , package : " swift-tools-support-core " ) ,
128
- ]
129
- }
130
188
let package = Package (
131
189
name: " SwiftPM " ,
132
190
platforms: [
133
191
. macOS( . v13) ,
134
192
. iOS( . v17) ,
135
193
. macCatalyst( . v17) ,
136
194
] ,
195
+ dependencies: dependencies,
137
196
products:
138
197
autoProducts. flatMap {
139
198
( includeDynamicLibrary ? [
@@ -272,7 +331,9 @@ let package = Package(
272
331
. product( name: " DequeModule " , package : " swift-collections " ) ,
273
332
. product( name: " OrderedCollections " , package : " swift-collections " ) ,
274
333
. product( name: " SystemPackage " , package : " swift-system " ) ,
275
- ] + swiftToolsCoreSupportAutoDeps,
334
+ ] + SwiftBuildFrameworkDependency( disabled: [
335
+ . product( name: " SwiftToolsSupport-auto " , package : " swift-tools-support-core " )
336
+ ] ) ,
276
337
exclude: [ " CMakeLists.txt " , " Vendor/README.md " ] ,
277
338
swiftSettings: swift6CompatibleExperimentalFeatures + [
278
339
. enableExperimentalFeature( " StrictConcurrency " ) ,
@@ -323,7 +384,9 @@ let package = Package(
323
384
. target(
324
385
/** Shim for llbuild library */
325
386
name: " SPMLLBuild " ,
326
- dependencies: [ " Basics " ] ,
387
+ dependencies: [ " Basics " ] + LLBuildFrameworkDependency( disabled: [
388
+ . product( name: " llbuildSwift " , package : " swift-llbuild " ) ,
389
+ ] ) ,
327
390
exclude: [ " CMakeLists.txt " ] ,
328
391
swiftSettings: commonExperimentalFeatures + [
329
392
. unsafeFlags( [ " -static " ] ) ,
@@ -335,7 +398,9 @@ let package = Package(
335
398
name: " SwiftFixIt " ,
336
399
dependencies: [
337
400
" Basics " ,
338
- ] + swiftTSCBasicsDeps + swiftSyntaxDependencies(
401
+ ] + SwiftBuildFrameworkDependency( disabled: [
402
+ . product( name: " TSCBasic " , package : " swift-tools-support-core " ) ,
403
+ ] ) + swiftSyntaxDependencies(
339
404
[ " SwiftDiagnostics " , " SwiftIDEUtils " , " SwiftParser " , " SwiftSyntax " ]
340
405
) ,
341
406
exclude: [ " CMakeLists.txt " ] ,
@@ -349,7 +414,9 @@ let package = Package(
349
414
name: " BinarySymbols " ,
350
415
dependencies: [
351
416
" Basics " ,
352
- ] + swiftTSCBasicsDeps,
417
+ ] + SwiftBuildFrameworkDependency( disabled: [
418
+ . product( name: " TSCBasic " , package : " swift-tools-support-core " ) ,
419
+ ] ) ,
353
420
exclude: [ " CMakeLists.txt " ] ,
354
421
swiftSettings: commonExperimentalFeatures + [
355
422
. unsafeFlags( [ " -static " ] ) ,
@@ -514,7 +581,9 @@ let package = Package(
514
581
" SPMLLBuild " ,
515
582
. product( name: " OrderedCollections " , package : " swift-collections " ) ,
516
583
" DriverSupport " ,
517
- ] + swiftDriverDeps,
584
+ ] + SwiftBuildFrameworkDependency( disabled: [
585
+ . product( name: " SwiftDriver " , package : " swift-driver " )
586
+ ] ) ,
518
587
exclude: [ " CMakeLists.txt " ] ,
519
588
swiftSettings: commonExperimentalFeatures + [
520
589
. unsafeFlags( [ " -static " ] ) ,
@@ -525,7 +594,9 @@ let package = Package(
525
594
dependencies: [
526
595
" Basics " ,
527
596
" PackageModel " ,
528
- ] + swiftDriverDeps,
597
+ ] + SwiftBuildFrameworkDependency( disabled: [
598
+ . product( name: " SwiftDriver " , package : " swift-driver " )
599
+ ] ) ,
529
600
exclude: [ " CMakeLists.txt " ] ,
530
601
swiftSettings: commonExperimentalFeatures + [
531
602
. unsafeFlags( [ " -static " ] ) ,
@@ -549,7 +620,11 @@ let package = Package(
549
620
dependencies: [
550
621
" SPMBuildCore " ,
551
622
" PackageGraph " ,
552
- ] ,
623
+ ] + SwiftBuildFrameworkDependency( enabled: [
624
+ . product( name: " SwiftBuild " , package : " swift-build " ) ,
625
+ // This is here to statically link the build service in the same executable as SwiftPM
626
+ . product( name: " SWBBuildService " , package : " swift-build " ) ,
627
+ ] ) ,
553
628
exclude: [ " CMakeLists.txt " , " README.md " ] ,
554
629
swiftSettings: commonExperimentalFeatures
555
630
) ,
@@ -825,7 +900,9 @@ let package = Package(
825
900
" SourceControl " ,
826
901
. product( name: " OrderedCollections " , package : " swift-collections " ) ,
827
902
" Workspace " ,
828
- ] + swiftTSCTestSupportDeps,
903
+ ] + SwiftBuildFrameworkDependency( disabled: [
904
+ . product( name: " TSCTestSupport " , package : " swift-tools-support-core " ) ,
905
+ ] ) ,
829
906
swiftSettings: [
830
907
. unsafeFlags( [ " -static " ] ) ,
831
908
]
@@ -1012,7 +1089,7 @@ package.targets.append(contentsOf: [
1012
1089
1013
1090
// rdar://101868275 "error: cannot find 'XCTAssertEqual' in scope" can affect almost any functional test, so we flat out
1014
1091
// disable them all until we know what is going on
1015
- if ProcessInfo . processInfo . environment [ " SWIFTCI_DISABLE_SDK_DEPENDENT_TESTS " ] == nil {
1092
+ if !defined ( " SWIFTCI_DISABLE_SDK_DEPENDENT_TESTS " ) {
1016
1093
package . targets. append ( contentsOf: [
1017
1094
. testTarget(
1018
1095
name: " FunctionalTests " ,
@@ -1060,109 +1137,17 @@ func swiftSyntaxDependencies(_ names: [String]) -> [Target.Dependency] {
1060
1137
/// This means that the swift-syntax symbols don't need to be statically linked, which allows us to stay below the
1061
1138
/// maximum number of exported symbols on Windows, in turn allowing us to build sourcekit-lsp using SwiftPM on Windows
1062
1139
/// and run its tests.
1063
- let buildDynamicSwiftSyntaxLibrary = ProcessInfo . processInfo . environment [ " SWIFTSYNTAX_BUILD_DYNAMIC_LIBRARY " ] != nil
1140
+ let buildDynamicSwiftSyntaxLibrary = defined ( " SWIFTSYNTAX_BUILD_DYNAMIC_LIBRARY " )
1064
1141
if buildDynamicSwiftSyntaxLibrary {
1065
1142
return [ . product( name: " _SwiftSyntaxDynamic " , package : " swift-syntax " ) ]
1066
1143
} else {
1067
1144
return names. map { . product( name: $0, package : " swift-syntax " ) }
1068
1145
}
1069
1146
}
1070
1147
1071
- // Add package dependency on llbuild when not bootstrapping.
1072
- //
1073
- // When bootstrapping SwiftPM, we can't use llbuild as a package dependency it
1074
- // will provided by whatever build system (SwiftCI, bootstrap script) is driving
1075
- // the build process. So, we only add these dependencies if SwiftPM is being
1076
- // built directly using SwiftPM. It is a bit unfortunate that we've add the
1077
- // package dependency like this but there is no other good way of expressing
1078
- // this right now.
1079
-
1080
- /// When not using local dependencies, the branch to use for llbuild and TSC repositories.
1081
- let relatedDependenciesBranch = " main "
1082
-
1083
- if ProcessInfo . processInfo. environment [ " SWIFTPM_LLBUILD_FWK " ] == nil {
1084
- if ProcessInfo . processInfo. environment [ " SWIFTCI_USE_LOCAL_DEPS " ] == nil {
1085
- package . dependencies += [
1086
- . package ( url: " https://github.com/swiftlang/swift-llbuild.git " , branch: relatedDependenciesBranch) ,
1087
- ]
1088
- } else {
1089
- // In Swift CI, use a local path to llbuild to interoperate with tools
1090
- // like `update-checkout`, which control the sources externally.
1091
- package . dependencies += [
1092
- . package ( name: " swift-llbuild " , path: " ../llbuild " ) ,
1093
- ]
1094
- }
1095
- package . targets. first ( where: { $0. name == " SPMLLBuild " } ) !. dependencies += [
1096
- . product( name: " llbuildSwift " , package : " swift-llbuild " ) ,
1097
- ]
1098
- }
1099
-
1100
- if ProcessInfo . processInfo. environment [ " SWIFTCI_USE_LOCAL_DEPS " ] == nil {
1101
- package . dependencies += [
1102
- // The 'swift-argument-parser' version declared here must match that
1103
- // used by 'swift-driver' and 'sourcekit-lsp'. Please coordinate
1104
- // dependency version changes here with those projects.
1105
- . package ( url: " https://github.com/apple/swift-argument-parser.git " , . upToNextMinor( from: " 1.5.1 " ) ) ,
1106
- . package ( url: " https://github.com/apple/swift-crypto.git " , . upToNextMinor( from: " 3.0.0 " ) ) ,
1107
- . package ( url: " https://github.com/swiftlang/swift-syntax.git " , branch: relatedDependenciesBranch) ,
1108
- . package ( url: " https://github.com/apple/swift-system.git " , from: " 1.1.1 " ) ,
1109
- . package ( url: " https://github.com/apple/swift-collections.git " , " 1.0.1 " ..< " 1.2.0 " ) ,
1110
- . package ( url: " https://github.com/apple/swift-certificates.git " , " 1.0.1 " ..< " 1.6.0 " ) ,
1111
- . package ( url: " https://github.com/swiftlang/swift-toolchain-sqlite.git " , from: " 1.0.0 " ) ,
1112
- // For use in previewing documentation
1113
- . package ( url: " https://github.com/swiftlang/swift-docc-plugin " , from: " 1.1.0 " ) ,
1114
- ]
1115
- if !swiftDriverDeps. isEmpty {
1116
- package . dependencies += [
1117
- . package ( url: " https://github.com/swiftlang/swift-tools-support-core.git " , branch: relatedDependenciesBranch) ,
1118
- . package ( url: " https://github.com/swiftlang/swift-driver.git " , branch: relatedDependenciesBranch) ,
1119
- ]
1120
- }
1121
- } else {
1122
- package . dependencies += [
1123
- . package ( path: " ../swift-argument-parser " ) ,
1124
- . package ( path: " ../swift-crypto " ) ,
1125
- . package ( path: " ../swift-syntax " ) ,
1126
- . package ( path: " ../swift-system " ) ,
1127
- . package ( path: " ../swift-collections " ) ,
1128
- . package ( path: " ../swift-certificates " ) ,
1129
- . package ( path: " ../swift-toolchain-sqlite " ) ,
1130
- ]
1131
- if !swiftDriverDeps. isEmpty {
1132
- package . dependencies += [
1133
- . package ( path: " ../swift-tools-support-core " ) ,
1134
- . package ( path: " ../swift-driver " ) ,
1135
- ]
1136
- }
1137
-
1138
- }
1139
-
1140
1148
/// If ENABLE_APPLE_PRODUCT_TYPES is set in the environment, then also define ENABLE_APPLE_PRODUCT_TYPES in each of the regular targets and test targets.
1141
1149
if ProcessInfo . processInfo. environment [ " ENABLE_APPLE_PRODUCT_TYPES " ] == " 1 " {
1142
1150
for target in package . targets. filter ( { $0. type == . regular || $0. type == . test } ) {
1143
1151
target. swiftSettings = ( target. swiftSettings ?? [ ] ) + [ . define( " ENABLE_APPLE_PRODUCT_TYPES " ) ]
1144
1152
}
1145
1153
}
1146
-
1147
- if !shoudUseSwiftBuildFramework {
1148
-
1149
- let swiftbuildsupport : Target = package . targets. first ( where: { $0. name == " SwiftBuildSupport " } ) !
1150
- swiftbuildsupport. dependencies += [
1151
- . product( name: " SwiftBuild " , package : " swift-build " ) ,
1152
- ]
1153
-
1154
- swiftbuildsupport. dependencies += [
1155
- // This is here to statically link the build service in the same executable as SwiftPM
1156
- . product( name: " SWBBuildService " , package : " swift-build " ) ,
1157
- ]
1158
-
1159
- if ProcessInfo . processInfo. environment [ " SWIFTCI_USE_LOCAL_DEPS " ] == nil {
1160
- package . dependencies += [
1161
- . package ( url: " https://github.com/swiftlang/swift-build.git " , branch: relatedDependenciesBranch) ,
1162
- ]
1163
- } else {
1164
- package . dependencies += [
1165
- . package ( path: " ../swift-build " ) ,
1166
- ]
1167
- }
1168
- }
0 commit comments