Skip to content

Commit e01f7a8

Browse files
committed
Build the side target in CMake but not in the package; the package ought to use the copy from the toolchain rather than rolling its own which other libraries won't know to link to
1 parent a38088b commit e01f7a8

File tree

6 files changed

+27
-31
lines changed

6 files changed

+27
-31
lines changed

Package.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,6 @@ let package = Package(
105105
)
106106
)
107107

108-
result.append(
109-
.library(
110-
name: "_Testing_ExperimentalInfrastructure",
111-
type: .dynamic,
112-
targets: ["_Testing_ExperimentalInfrastructure"]
113-
)
114-
)
115-
116108
return result
117109
}(),
118110

@@ -134,7 +126,6 @@ let package = Package(
134126
dependencies: [
135127
"_TestDiscovery",
136128
"_TestingInternals",
137-
"_Testing_ExperimentalInfrastructure",
138129
"TestingMacros",
139130
],
140131
exclude: ["CMakeLists.txt", "Testing.swiftcrossimport"],
@@ -218,13 +209,6 @@ let package = Package(
218209
cxxSettings: .packageSettings,
219210
swiftSettings: .packageSettings + .enableLibraryEvolution()
220211
),
221-
.target(
222-
name: "_Testing_ExperimentalInfrastructure",
223-
dependencies: ["_TestingInternals",],
224-
exclude: ["CMakeLists.txt"],
225-
cxxSettings: .packageSettings,
226-
swiftSettings: .packageSettings + .enableLibraryEvolution()
227-
),
228212

229213
// Cross-import overlays (not supported by Swift Package Manager)
230214
.target(

Sources/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ endif()
104104
include(AvailabilityDefinitions)
105105
include(CompilerSettings)
106106
add_subdirectory(_TestDiscovery)
107-
add_subdirectory(_Testing_ExperimentalInfrastructure)
107+
add_subdirectory(_TestingInfrastructure)
108108
add_subdirectory(_TestingInternals)
109109
add_subdirectory(Overlays)
110110
add_subdirectory(Testing)

Sources/Testing/Events/Event+FallbackHandler.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
private import _Testing_ExperimentalInfrastructure
11+
#if canImport(_TestingInfrastructure)
12+
private import _TestingInfrastructure
13+
#endif
1214

1315
extension Event {
1416
/// Attempt to handle an event encoded as JSON as if it had been generated in
@@ -62,6 +64,7 @@ extension Event {
6264
}
6365
}
6466

67+
#if canImport(_TestingInfrastructure)
6568
/// The fallback event handler to set when Swift Testing is the active testing
6669
/// library.
6770
private static let _fallbackEventHandler: FallbackEventHandler = { recordJSONSchemaVersionNumber, recordJSONBaseAddress, recordJSONByteCount, _ in
@@ -73,10 +76,15 @@ extension Event {
7376
try! Self.handle(recordJSON, encodedWith: abi)
7477
}
7578
}
79+
#endif
7680

7781
/// The implementation of ``installFallbackEventHandler()``.
7882
private static let _installFallbackHandler: Bool = {
79-
_Testing_ExperimentalInfrastructure.installFallbackEventHandler(Self._fallbackEventHandler)
83+
#if canImport(_TestingInfrastructure)
84+
_swift_testing_installFallbackEventHandler(Self._fallbackEventHandler)
85+
#else
86+
false
87+
#endif
8088
}()
8189

8290
/// Install the testing library's fallback event handler.
@@ -95,7 +103,8 @@ extension Event {
95103
/// currently-installed handler belongs to the testing library, returns
96104
/// `false`.
97105
borrowing func postToFallbackHandler(in context: borrowing Context) -> Bool {
98-
guard let fallbackEventHandler = _Testing_ExperimentalInfrastructure.fallbackEventHandler() else {
106+
#if canImport(_TestingInfrastructure)
107+
guard let fallbackEventHandler = _swift_testing_getFallbackEventHandler() else {
99108
// No fallback event handler is installed.
100109
return false
101110
}
@@ -116,5 +125,8 @@ extension Event {
116125
}
117126
encodeAndInvoke(self, context)
118127
return true
128+
#else
129+
return false
130+
#endif
119131
}
120132
}

Sources/_Testing_ExperimentalInfrastructure/CMakeLists.txt renamed to Sources/_TestingInfrastructure/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(_Testing_ExperimentalInfrastructure
9+
add_library(_TestingInfrastructure
1010
FallbackEventHandler.swift)
1111

12-
target_link_libraries(_Testing_ExperimentalInfrastructure PRIVATE
12+
target_link_libraries(_TestingInfrastructure PRIVATE
1313
_TestingInternals)
1414
if(NOT BUILD_SHARED_LIBS)
1515
# When building a static library, tell clients to autolink the internal
1616
# libraries.
1717
target_compile_options(Testing PRIVATE
1818
"SHELL:-Xfrontend -public-autolink-library -Xfrontend _TestingInternals")
1919
endif()
20-
target_compile_options(_Testing_ExperimentalInfrastructure PRIVATE
20+
target_compile_options(_TestingInfrastructure PRIVATE
2121
-enable-library-evolution
22-
-emit-module-interface -emit-module-interface-path $<TARGET_PROPERTY:_Testing_ExperimentalInfrastructure,Swift_MODULE_DIRECTORY>/_Testing_ExperimentalInfrastructure.swiftinterface)
22+
-emit-module-interface -emit-module-interface-path $<TARGET_PROPERTY:_TestingInfrastructure,Swift_MODULE_DIRECTORY>/_TestingInfrastructure.swiftinterface)
2323

24-
_swift_testing_install_target(_Testing_ExperimentalInfrastructure)
24+
_swift_testing_install_target(_TestingInfrastructure)

Sources/_Testing_ExperimentalInfrastructure/FallbackEventHandler.swift renamed to Sources/_TestingInfrastructure/FallbackEventHandler.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ package typealias FallbackEventHandler = @Sendable @convention(c) (
5454
/// to calls to ``setFallbackEventHandler(_:)``. If you need to atomically
5555
/// exchange the previous value with a new value, call
5656
/// ``setFallbackEventHandler(_:)`` and store its returned value.
57-
@_cdecl("swift_testing_getFallbackEventHandler")
57+
@_cdecl("_swift_testing_getFallbackEventHandler")
5858
@usableFromInline
59-
package func fallbackEventHandler() -> FallbackEventHandler? {
59+
package func _swift_testing_getFallbackEventHandler() -> FallbackEventHandler? {
6060
#if SWT_TARGET_OS_APPLE && !SWT_NO_OS_UNFAIR_LOCK
6161
return _fallbackEventHandler.withUnsafeMutablePointers { fallbackEventHandler, lock in
6262
os_unfair_lock_lock(lock)
@@ -82,9 +82,9 @@ package func fallbackEventHandler() -> FallbackEventHandler? {
8282
/// The fallback event handler can only be installed once per process, typically
8383
/// by the first testing library to run. If this function has already been
8484
/// called and the handler set, it does not replace the previous handler.
85-
@_cdecl("swift_testing_installFallbackEventHandler")
85+
@_cdecl("_swift_testing_installFallbackEventHandler")
8686
@usableFromInline
87-
package func installFallbackEventHandler(_ handler: FallbackEventHandler) -> CBool {
87+
package func _swift_testing_installFallbackEventHandler(_ handler: FallbackEventHandler) -> CBool {
8888
#if SWT_TARGET_OS_APPLE && !SWT_NO_OS_UNFAIR_LOCK
8989
return _fallbackEventHandler.withUnsafeMutablePointers { fallbackEventHandler, lock in
9090
os_unfair_lock_lock(lock)

Tests/TestingTests/EventTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ struct EventTests {
8181

8282
// MARK: -
8383

84-
#if canImport(Foundation)
85-
private import _Testing_ExperimentalInfrastructure
84+
#if canImport(_TestingInfrastructure) && canImport(Foundation)
85+
private import _TestingInfrastructure
8686
import Foundation
8787

8888
private func MockXCTAssert(_ condition: Bool, _ message: String, _ sourceLocation: SourceLocation = #_sourceLocation) {

0 commit comments

Comments
 (0)