Skip to content

Commit 43b6f88

Browse files
authored
[6.1] Suppress .unsafeFlags() in Package.swift when tagging for release. (#993)
- **Explanation**: Don't include `.unsafeFlags()` in Package.swift in tagged releases so that they can be used as package dependencies. - **Scope**: Anybody who wants to include Swift Testing as a package dependency rather than using the toolchain or Xcode copy. - **Issues**: N/A - **Original PRs**: #991 - **Risk**: Low (no obvious risk) - **Testing**: Tagged the branch locally and built. Build was successful. - **Reviewers**: @stmontgomery @briancroom
1 parent 336fad6 commit 43b6f88

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

Diff for: Package.swift

+29-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
import PackageDescription
1414
import CompilerPluginSupport
1515

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+
1623
let package = Package(
1724
name: "swift-testing",
1825

@@ -67,19 +74,21 @@ let package = Package(
6774
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
6875
],
6976
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]()
7479

7580
// The only target which needs the ability to import this macro
7681
// implementation target's module is its unit test target. Users of the
7782
// macros this target implements use them via their declarations in the
7883
// Testing module. This target's module is never distributed to users,
7984
// but as an additional guard against accidental misuse, this specifies
8085
// 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+
}()
8392
),
8493

8594
// "Support" targets: These contain C family code and are used exclusively
@@ -122,14 +131,23 @@ extension Array where Element == PackageDescription.SwiftSetting {
122131
/// Settings intended to be applied to every Swift target in this package.
123132
/// Analogous to project-level build settings in an Xcode project.
124133
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 += [
127141
.enableUpcomingFeature("ExistentialAny"),
128142
.enableExperimentalFeature("SuppressedAssociatedTypes"),
129143

130144
.enableExperimentalFeature("AccessLevelOnImport"),
131145
.enableUpcomingFeature("InternalImportsByDefault"),
132146

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+
133151
.define("SWT_TARGET_OS_APPLE", .when(platforms: [.macOS, .iOS, .macCatalyst, .watchOS, .tvOS, .visionOS])),
134152

135153
.define("SWT_NO_EXIT_TESTS", .when(platforms: [.iOS, .watchOS, .tvOS, .visionOS, .wasi, .android])),
@@ -138,6 +156,8 @@ extension Array where Element == PackageDescription.SwiftSetting {
138156
.define("SWT_NO_DYNAMIC_LINKING", .when(platforms: [.wasi])),
139157
.define("SWT_NO_PIPES", .when(platforms: [.wasi])),
140158
]
159+
160+
return result
141161
}
142162

143163
/// Settings which define commonly-used OS availability macros.
@@ -175,7 +195,7 @@ extension Array where Element == PackageDescription.CXXSetting {
175195
]
176196

177197
// Capture the testing library's version as a C++ string constant.
178-
if let git = Context.gitInformation {
198+
if let git {
179199
let testingLibraryVersion = if let tag = git.currentTag {
180200
tag
181201
} else if git.hasUncommittedChanges {

0 commit comments

Comments
 (0)