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
@@ -67,19 +74,21 @@ let package = Package(
67
74
. product( name: " SwiftCompilerPlugin " , package : " swift-syntax " ) ,
68
75
] ,
69
76
exclude: [ " CMakeLists.txt " ] ,
70
- swiftSettings: . packageSettings + [
71
- // When building as a package, the macro plugin always builds as an
72
- // executable rather than a library.
73
- . define( " SWT_NO_LIBRARY_MACRO_PLUGINS " ) ,
77
+ swiftSettings: . packageSettings + {
78
+ var result = [ PackageDescription . SwiftSetting] ( )
74
79
75
80
// The only target which needs the ability to import this macro
76
81
// implementation target's module is its unit test target. Users of the
77
82
// macros this target implements use them via their declarations in the
78
83
// Testing module. This target's module is never distributed to users,
79
84
// but as an additional guard against accidental misuse, this specifies
80
85
// the unit test target as the only allowable client.
81
- . unsafeFlags( [ " -Xfrontend " , " -allowable-client " , " -Xfrontend " , " TestingMacrosTests " ] ) ,
82
- ]
86
+ if buildingForDevelopment {
87
+ result. append ( . unsafeFlags( [ " -Xfrontend " , " -allowable-client " , " -Xfrontend " , " TestingMacrosTests " ] ) )
88
+ }
89
+
90
+ return result
91
+ } ( )
83
92
) ,
84
93
85
94
// "Support" targets: These contain C family code and are used exclusively
@@ -122,14 +131,23 @@ extension Array where Element == PackageDescription.SwiftSetting {
122
131
/// Settings intended to be applied to every Swift target in this package.
123
132
/// Analogous to project-level build settings in an Xcode project.
124
133
static var packageSettings : Self {
125
- availabilityMacroSettings + [
126
- . unsafeFlags( [ " -require-explicit-sendable " ] ) ,
134
+ var result = availabilityMacroSettings
135
+
136
+ if buildingForDevelopment {
137
+ result. append ( . unsafeFlags( [ " -require-explicit-sendable " ] ) )
138
+ }
139
+
140
+ result += [
127
141
. enableUpcomingFeature( " ExistentialAny " ) ,
128
142
. enableExperimentalFeature( " SuppressedAssociatedTypes " ) ,
129
143
130
144
. enableExperimentalFeature( " AccessLevelOnImport " ) ,
131
145
. enableUpcomingFeature( " InternalImportsByDefault " ) ,
132
146
147
+ // When building as a package, the macro plugin always builds as an
148
+ // executable rather than a library.
149
+ . define( " SWT_NO_LIBRARY_MACRO_PLUGINS " ) ,
150
+
133
151
. define( " SWT_TARGET_OS_APPLE " , . when( platforms: [ . macOS, . iOS, . macCatalyst, . watchOS, . tvOS, . visionOS] ) ) ,
134
152
135
153
. define( " SWT_NO_EXIT_TESTS " , . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ,
@@ -138,6 +156,8 @@ extension Array where Element == PackageDescription.SwiftSetting {
138
156
. define( " SWT_NO_DYNAMIC_LINKING " , . when( platforms: [ . wasi] ) ) ,
139
157
. define( " SWT_NO_PIPES " , . when( platforms: [ . wasi] ) ) ,
140
158
]
159
+
160
+ return result
141
161
}
142
162
143
163
/// Settings which define commonly-used OS availability macros.
@@ -175,7 +195,7 @@ extension Array where Element == PackageDescription.CXXSetting {
175
195
]
176
196
177
197
// Capture the testing library's version as a C++ string constant.
178
- if let git = Context . gitInformation {
198
+ if let git {
179
199
let testingLibraryVersion = if let tag = git. currentTag {
180
200
tag
181
201
} else if git. hasUncommittedChanges {
0 commit comments