13
13
import PackageDescription
14
14
import CompilerPluginSupport
15
15
16
+ /// Information about the current state of the package's git repository.
17
+ let git = Context . gitInformation
18
+
19
+ /// Whether or not this package is being built for development rather than
20
+ /// distribution as a package dependency.
21
+ let buildingForDevelopment = ( git? . currentTag == nil )
22
+
16
23
let package = Package (
17
24
name: " swift-testing " ,
18
25
@@ -55,9 +62,7 @@ let package = Package(
55
62
] ,
56
63
exclude: [ " CMakeLists.txt " , " Testing.swiftcrossimport " ] ,
57
64
cxxSettings: . packageSettings,
58
- swiftSettings: . packageSettings + [
59
- . enableLibraryEvolution( ) ,
60
- ] ,
65
+ swiftSettings: . packageSettings + . enableLibraryEvolution( ) ,
61
66
linkerSettings: [
62
67
. linkedLibrary( " execinfo " , . when( platforms: [ . custom( " freebsd " ) , . openbsd] ) )
63
68
]
@@ -86,19 +91,21 @@ let package = Package(
86
91
. product( name: " SwiftCompilerPlugin " , package : " swift-syntax " ) ,
87
92
] ,
88
93
exclude: [ " CMakeLists.txt " ] ,
89
- swiftSettings: . packageSettings + [
90
- // When building as a package, the macro plugin always builds as an
91
- // executable rather than a library.
92
- . define( " SWT_NO_LIBRARY_MACRO_PLUGINS " ) ,
94
+ swiftSettings: . packageSettings + {
95
+ var result = [ PackageDescription . SwiftSetting] ( )
93
96
94
97
// The only target which needs the ability to import this macro
95
98
// implementation target's module is its unit test target. Users of the
96
99
// macros this target implements use them via their declarations in the
97
100
// Testing module. This target's module is never distributed to users,
98
101
// but as an additional guard against accidental misuse, this specifies
99
102
// the unit test target as the only allowable client.
100
- . unsafeFlags( [ " -Xfrontend " , " -allowable-client " , " -Xfrontend " , " TestingMacrosTests " ] ) ,
101
- ]
103
+ if buildingForDevelopment {
104
+ result. append ( . unsafeFlags( [ " -Xfrontend " , " -allowable-client " , " -Xfrontend " , " TestingMacrosTests " ] ) )
105
+ }
106
+
107
+ return result
108
+ } ( )
102
109
) ,
103
110
104
111
// "Support" targets: These contain C family code and are used exclusively
@@ -116,9 +123,7 @@ let package = Package(
116
123
" Testing " ,
117
124
] ,
118
125
path: " Sources/Overlays/_Testing_CoreGraphics " ,
119
- swiftSettings: . packageSettings + [
120
- . enableLibraryEvolution( ) ,
121
- ]
126
+ swiftSettings: . packageSettings + . enableLibraryEvolution( )
122
127
) ,
123
128
. target(
124
129
name: " _Testing_Foundation " ,
@@ -127,12 +132,10 @@ let package = Package(
127
132
] ,
128
133
path: " Sources/Overlays/_Testing_Foundation " ,
129
134
exclude: [ " CMakeLists.txt " ] ,
130
- swiftSettings: . packageSettings + [
131
- // The Foundation module only has Library Evolution enabled on Apple
132
- // platforms, and since this target's module publicly imports Foundation,
133
- // it can only enable Library Evolution itself on those platforms.
134
- . enableLibraryEvolution( applePlatformsOnly: true ) ,
135
- ]
135
+ // The Foundation module only has Library Evolution enabled on Apple
136
+ // platforms, and since this target's module publicly imports Foundation,
137
+ // it can only enable Library Evolution itself on those platforms.
138
+ swiftSettings: . packageSettings + . enableLibraryEvolution( applePlatformsOnly: true ) ,
136
139
) ,
137
140
138
141
// Utility targets: These are utilities intended for use when developing
@@ -167,14 +170,23 @@ extension Array where Element == PackageDescription.SwiftSetting {
167
170
/// Settings intended to be applied to every Swift target in this package.
168
171
/// Analogous to project-level build settings in an Xcode project.
169
172
static var packageSettings : Self {
170
- availabilityMacroSettings + [
171
- . unsafeFlags( [ " -require-explicit-sendable " ] ) ,
173
+ var result = availabilityMacroSettings
174
+
175
+ if buildingForDevelopment {
176
+ result. append ( . unsafeFlags( [ " -require-explicit-sendable " ] ) )
177
+ }
178
+
179
+ result += [
172
180
. enableUpcomingFeature( " ExistentialAny " ) ,
173
181
. enableExperimentalFeature( " SuppressedAssociatedTypes " ) ,
174
182
175
183
. enableExperimentalFeature( " AccessLevelOnImport " ) ,
176
184
. enableUpcomingFeature( " InternalImportsByDefault " ) ,
177
185
186
+ // When building as a package, the macro plugin always builds as an
187
+ // executable rather than a library.
188
+ . define( " SWT_NO_LIBRARY_MACRO_PLUGINS " ) ,
189
+
178
190
. define( " SWT_TARGET_OS_APPLE " , . when( platforms: [ . macOS, . iOS, . macCatalyst, . watchOS, . tvOS, . visionOS] ) ) ,
179
191
180
192
. define( " SWT_NO_EXIT_TESTS " , . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ,
@@ -183,6 +195,8 @@ extension Array where Element == PackageDescription.SwiftSetting {
183
195
. define( " SWT_NO_DYNAMIC_LINKING " , . when( platforms: [ . wasi] ) ) ,
184
196
. define( " SWT_NO_PIPES " , . when( platforms: [ . wasi] ) ) ,
185
197
]
198
+
199
+ return result
186
200
}
187
201
188
202
/// Settings which define commonly-used OS availability macros.
@@ -203,17 +217,25 @@ extension Array where Element == PackageDescription.SwiftSetting {
203
217
. enableExperimentalFeature( " AvailabilityMacro=_distantFuture:macOS 99.0, iOS 99.0, watchOS 99.0, tvOS 99.0, visionOS 99.0 " ) ,
204
218
]
205
219
}
206
- }
207
220
208
- extension PackageDescription . SwiftSetting {
209
221
/// Create a Swift setting which enables Library Evolution, optionally
210
222
/// constraining it to only Apple platforms.
211
223
///
212
224
/// - Parameters:
213
225
/// - applePlatformsOnly: Whether to constrain this setting to only Apple
214
226
/// platforms.
215
227
static func enableLibraryEvolution( applePlatformsOnly: Bool = false ) -> Self {
216
- unsafeFlags ( [ " -enable-library-evolution " ] , . when( platforms: applePlatformsOnly ? [ . macOS, . iOS, . macCatalyst, . watchOS, . tvOS, . visionOS] : [ ] ) )
228
+ var result = [ PackageDescription . SwiftSetting] ( )
229
+
230
+ if buildingForDevelopment {
231
+ var condition : BuildSettingCondition ?
232
+ if applePlatformsOnly {
233
+ condition = . when( platforms: [ . macOS, . iOS, . macCatalyst, . watchOS, . tvOS, . visionOS] )
234
+ }
235
+ result. append ( . unsafeFlags( [ " -enable-library-evolution " ] , condition) )
236
+ }
237
+
238
+ return result
217
239
}
218
240
}
219
241
@@ -232,7 +254,7 @@ extension Array where Element == PackageDescription.CXXSetting {
232
254
]
233
255
234
256
// Capture the testing library's version as a C++ string constant.
235
- if let git = Context . gitInformation {
257
+ if let git {
236
258
let testingLibraryVersion = if let tag = git. currentTag {
237
259
tag
238
260
} else if git. hasUncommittedChanges {
0 commit comments