Skip to content

Commit a4070bc

Browse files
authored
Enable Library Evolution in package builds for public library targets (#951)
This modifies `Package.swift` to enable Library Evolution for builds of the package. ### Motivation: I recently landed a change (#931) which passed our project-level CI but later failed in Swift CI. The difference ended up being due to the latter building with Library Evolution (LE) enabled, whereas our project-level CI builds via SwiftPM and does not enable LE. The change was reverted (#950) but this revealed a gap in our testing strategy. We should always build these targets with LE enabled. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated. Fixes rdar://144655439
1 parent e1fd7c7 commit a4070bc

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

Package.swift

+24-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ let package = Package(
5555
],
5656
exclude: ["CMakeLists.txt", "Testing.swiftcrossimport"],
5757
cxxSettings: .packageSettings,
58-
swiftSettings: .packageSettings,
58+
swiftSettings: .packageSettings + [
59+
.enableLibraryEvolution(),
60+
],
5961
linkerSettings: [
6062
.linkedLibrary("execinfo", .when(platforms: [.custom("freebsd"), .openbsd]))
6163
]
@@ -114,7 +116,9 @@ let package = Package(
114116
"Testing",
115117
],
116118
path: "Sources/Overlays/_Testing_CoreGraphics",
117-
swiftSettings: .packageSettings
119+
swiftSettings: .packageSettings + [
120+
.enableLibraryEvolution(),
121+
]
118122
),
119123
.target(
120124
name: "_Testing_Foundation",
@@ -123,7 +127,12 @@ let package = Package(
123127
],
124128
path: "Sources/Overlays/_Testing_Foundation",
125129
exclude: ["CMakeLists.txt"],
126-
swiftSettings: .packageSettings
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+
]
127136
),
128137
],
129138

@@ -186,6 +195,18 @@ extension Array where Element == PackageDescription.SwiftSetting {
186195
}
187196
}
188197

198+
extension PackageDescription.SwiftSetting {
199+
/// Create a Swift setting which enables Library Evolution, optionally
200+
/// constraining it to only Apple platforms.
201+
///
202+
/// - Parameters:
203+
/// - applePlatformsOnly: Whether to constrain this setting to only Apple
204+
/// platforms.
205+
static func enableLibraryEvolution(applePlatformsOnly: Bool = false) -> Self {
206+
unsafeFlags(["-enable-library-evolution"], .when(platforms: applePlatformsOnly ? [.macOS, .iOS, .macCatalyst, .watchOS, .tvOS, .visionOS] : []))
207+
}
208+
}
209+
189210
extension Array where Element == PackageDescription.CXXSetting {
190211
/// Settings intended to be applied to every C++ target in this package.
191212
/// Analogous to project-level build settings in an Xcode project.

Sources/Testing/Running/Configuration.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public struct Configuration: Sendable {
218218
/// property is pre-configured. Otherwise, the default value of this property
219219
/// records an issue indicating that it has not been configured.
220220
@_spi(Experimental)
221-
public var exitTestHandler: ExitTest.Handler = { _ in
221+
public var exitTestHandler: ExitTest.Handler = { exitTest in
222222
throw SystemError(description: "Exit test support has not been implemented by the current testing infrastructure.")
223223
}
224224
#endif

0 commit comments

Comments
 (0)