From 7b3d669b0120dbbb154e0fa832efe9efba10661e Mon Sep 17 00:00:00 2001 From: Stuart Montgomery Date: Tue, 11 Feb 2025 21:13:20 -0600 Subject: [PATCH 1/3] Enable Library Evolution in package builds for public library targets Fixes rdar://144655439 --- Package.swift | 16 +++++++++++++--- Sources/Testing/Running/Configuration.swift | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index 4a22b98e2..e38ae492b 100644 --- a/Package.swift +++ b/Package.swift @@ -55,7 +55,7 @@ let package = Package( ], exclude: ["CMakeLists.txt", "Testing.swiftcrossimport"], cxxSettings: .packageSettings, - swiftSettings: .packageSettings, + swiftSettings: .publicLibraryTargetSettings, linkerSettings: [ .linkedLibrary("execinfo", .when(platforms: [.custom("freebsd"), .openbsd])) ] @@ -114,7 +114,7 @@ let package = Package( "Testing", ], path: "Sources/Overlays/_Testing_CoreGraphics", - swiftSettings: .packageSettings + swiftSettings: .publicLibraryTargetSettings ), .target( name: "_Testing_Foundation", @@ -123,7 +123,7 @@ let package = Package( ], path: "Sources/Overlays/_Testing_Foundation", exclude: ["CMakeLists.txt"], - swiftSettings: .packageSettings + swiftSettings: .publicLibraryTargetSettings ), ], @@ -166,6 +166,16 @@ extension Array where Element == PackageDescription.SwiftSetting { ] } + /// Settings intended to be applied to every public Swift library target in + /// this package. + static var publicLibraryTargetSettings: Self { + packageSettings + [ + // Enable Library Evolution to match the way this library is built for + // distribution. + .unsafeFlags(["-enable-library-evolution"]), + ] + } + /// Settings which define commonly-used OS availability macros. /// /// These leverage a pseudo-experimental feature in the Swift compiler for diff --git a/Sources/Testing/Running/Configuration.swift b/Sources/Testing/Running/Configuration.swift index f4ae59813..e0c15b6fb 100644 --- a/Sources/Testing/Running/Configuration.swift +++ b/Sources/Testing/Running/Configuration.swift @@ -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 throw SystemError(description: "Exit test support has not been implemented by the current testing infrastructure.") } #endif From e2f3fe4ecdd6999dca7b0da70ebb5850a930453b Mon Sep 17 00:00:00 2001 From: Stuart Montgomery Date: Wed, 12 Feb 2025 10:39:47 -0600 Subject: [PATCH 2/3] Limit library evolution to only Apple platforms for the Foundation cross-import overlay --- Package.swift | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/Package.swift b/Package.swift index e38ae492b..555829668 100644 --- a/Package.swift +++ b/Package.swift @@ -55,7 +55,9 @@ let package = Package( ], exclude: ["CMakeLists.txt", "Testing.swiftcrossimport"], cxxSettings: .packageSettings, - swiftSettings: .publicLibraryTargetSettings, + swiftSettings: .packageSettings + [ + .enableLibraryEvolution(), + ], linkerSettings: [ .linkedLibrary("execinfo", .when(platforms: [.custom("freebsd"), .openbsd])) ] @@ -114,7 +116,9 @@ let package = Package( "Testing", ], path: "Sources/Overlays/_Testing_CoreGraphics", - swiftSettings: .publicLibraryTargetSettings + swiftSettings: .packageSettings + [ + .enableLibraryEvolution(), + ] ), .target( name: "_Testing_Foundation", @@ -123,7 +127,9 @@ let package = Package( ], path: "Sources/Overlays/_Testing_Foundation", exclude: ["CMakeLists.txt"], - swiftSettings: .publicLibraryTargetSettings + swiftSettings: .packageSettings + [ + .enableLibraryEvolution(applePlatformsOnly: true), + ] ), ], @@ -166,16 +172,6 @@ extension Array where Element == PackageDescription.SwiftSetting { ] } - /// Settings intended to be applied to every public Swift library target in - /// this package. - static var publicLibraryTargetSettings: Self { - packageSettings + [ - // Enable Library Evolution to match the way this library is built for - // distribution. - .unsafeFlags(["-enable-library-evolution"]), - ] - } - /// Settings which define commonly-used OS availability macros. /// /// These leverage a pseudo-experimental feature in the Swift compiler for @@ -196,6 +192,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. From e8fd2e91ac67d900900c2092ed83094a052c1554 Mon Sep 17 00:00:00 2001 From: Stuart Montgomery Date: Wed, 12 Feb 2025 13:24:10 -0600 Subject: [PATCH 3/3] Add explanatory comment --- Package.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Package.swift b/Package.swift index 555829668..43337b0dc 100644 --- a/Package.swift +++ b/Package.swift @@ -128,6 +128,9 @@ let package = Package( path: "Sources/Overlays/_Testing_Foundation", exclude: ["CMakeLists.txt"], 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), ] ),