Skip to content

Enable Library Evolution in package builds for public library targets #951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ let package = Package(
],
exclude: ["CMakeLists.txt", "Testing.swiftcrossimport"],
cxxSettings: .packageSettings,
swiftSettings: .packageSettings,
swiftSettings: .packageSettings + [
.enableLibraryEvolution(),
],
linkerSettings: [
.linkedLibrary("execinfo", .when(platforms: [.custom("freebsd"), .openbsd]))
]
Expand Down Expand Up @@ -114,7 +116,9 @@ let package = Package(
"Testing",
],
path: "Sources/Overlays/_Testing_CoreGraphics",
swiftSettings: .packageSettings
swiftSettings: .packageSettings + [
.enableLibraryEvolution(),
]
),
.target(
name: "_Testing_Foundation",
Expand All @@ -123,7 +127,12 @@ let package = Package(
],
path: "Sources/Overlays/_Testing_Foundation",
exclude: ["CMakeLists.txt"],
swiftSettings: .packageSettings
swiftSettings: .packageSettings + [
// The Foundation module only has Library Evolution enabled on Apple
// platforms, and since this target's module publicly imports Foundation,
// it can only enable Library Evolution itself on those platforms.
.enableLibraryEvolution(applePlatformsOnly: true),
]
),
],

Expand Down Expand Up @@ -186,6 +195,18 @@ extension Array where Element == PackageDescription.SwiftSetting {
}
}

extension PackageDescription.SwiftSetting {
/// Create a Swift setting which enables Library Evolution, optionally
/// constraining it to only Apple platforms.
///
/// - Parameters:
/// - applePlatformsOnly: Whether to constrain this setting to only Apple
/// platforms.
static func enableLibraryEvolution(applePlatformsOnly: Bool = false) -> Self {
unsafeFlags(["-enable-library-evolution"], .when(platforms: applePlatformsOnly ? [.macOS, .iOS, .macCatalyst, .watchOS, .tvOS, .visionOS] : []))
}
}

extension Array where Element == PackageDescription.CXXSetting {
/// Settings intended to be applied to every C++ target in this package.
/// Analogous to project-level build settings in an Xcode project.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Testing/Running/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public struct Configuration: Sendable {
/// property is pre-configured. Otherwise, the default value of this property
/// records an issue indicating that it has not been configured.
@_spi(Experimental)
public var exitTestHandler: ExitTest.Handler = { _ in
public var exitTestHandler: ExitTest.Handler = { exitTest in
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After I enabled Library Evolution, I got a compiler crash when building with a main snapshot toolchain which has asserts enabled:

Begin Error in Function: '$s7Testing13ConfigurationV15exitTestHandleryAA04ExitD9ArtifactsVAA02__fD0VYaYbKcvpfiAfHYaYbKcfU_'
Found outside of lifetime use?!
Value:   %2 = load_borrow %1 : $*__ExitTest              // users: %8, %4, %3
Consuming User:   end_borrow %2 : $__ExitTest                     // id: %4
Non Consuming User:   debug_value %2 : $__ExitTest, let, name "_0", argno 1 // id: %8
Block: bb0

End Error in Function: '$s7Testing13ConfigurationV15exitTestHandleryAA04ExitD9ArtifactsVAA02__fD0VYaYbKcvpfiAfHYaYbKcfU_'
Found ownership error?!
1.  Apple Swift version 6.2-dev (LLVM 5805166b4c9eb06, Swift 57234f8034befac)
2.  Compiling with the current language version
3.  While evaluating request ExecuteSILPipelineRequest(Run pipelines { Non-Diagnostic Mandatory Optimizations, Serialization, Rest of Onone } on SIL for Testing)
4.  While running pass #679 SILFunctionTransform "OwnershipModelEliminator" on SILFunction "@$s7Testing13ConfigurationV15exitTestHandleryAA04ExitD9ArtifactsVAA02__fD0VYaYbKcvpfiAfHYaYbKcfU_".
 for expression at [/Users/stuart/Work/swift-testing/Sources/Testing/Running/Configuration.swift:221:50 - line:223:3] RangeText="{ (_: borrowing ExitTest) throws -> ExitTestArtifacts in
    throw SystemError(description: "Exit test support has not been implemented by the current testing infrastructure.")
  "
5.  Found verification error when verifying before lowering ownership. Please re-run with -sil-verify-all to identify the actual pass that introduced the verification error.
6.  While verifying SIL function "@$s7Testing13ConfigurationV15exitTestHandleryAA04ExitD9ArtifactsVAA02__fD0VYaYbKcvpfiAfHYaYbKcfU_".
 for expression at [/Users/stuart/Work/swift-testing/Sources/Testing/Running/Configuration.swift:221:50 - line:223:3] RangeText="{ (_: borrowing ExitTest) throws -> ExitTestArtifacts in
    throw SystemError(description: "Exit test support has not been implemented by the current testing infrastructure.")
  "

The closure parameter is of type borrowing ExitTest, and as a workaround I found simply giving it a name instead of the wildcard _ resolves the crash. I can file an issue to track that separately tomorrow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's bizarre. Okay.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think this might be the same issue as the one you just had to work around? @jckarter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a different issue than swiftlang/swift#79304

throw SystemError(description: "Exit test support has not been implemented by the current testing infrastructure.")
}
#endif
Expand Down