From 5cd77e7eff2dcb1383603f36f6a940134a039d1c Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sun, 17 Nov 2024 15:36:49 -0700 Subject: [PATCH 1/4] Documentation: Update CMake.md to use the ABI entry point The SwiftPM entry point is unstable and the new ABIv0 entry point has already been added to the library. --- Documentation/CMake.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Documentation/CMake.md b/Documentation/CMake.md index e846f5641..34cbf668c 100644 --- a/Documentation/CMake.md +++ b/Documentation/CMake.md @@ -59,21 +59,28 @@ endif() ## Add an entry point You must include a source file in your test executable target with a -`@main` entry point. The following example uses the SwiftPM entry point: +`@main` entry point. ```swift -import Testing +import Foundation +@_spi(ForToolsIntegrationOnly) import Testing @main struct Runner { - static func main() async { - await Testing.__swiftPMEntryPoint() as Never + static func main() async throws { + let configurationJSON: UnsafeRawBufferPointer? = nil + let recordHandler: @Sendable (UnsafeRawBufferPointer) -> Void = { _ in } + + if try await ABIv0.entryPoint(configurationJSON, recordHandler) { + exit(EXIT_SUCCESS) + } else { + exit(EXIT_FAILURE) + } } } ``` -> [!WARNING] -> The entry point is expected to change to an entry point designed for other -> build systems prior to the initial stable release of Swift Testing. +For more information on the input configuration and output records of the ABI entry +point, refer to the [ABI documentation](ABI/JSON.md) ## Integrate with CTest From c45c8010b4c12a5f850c9bc989fe079465e57e1b Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Tue, 10 Dec 2024 11:42:28 -0700 Subject: [PATCH 2/4] Documentation: Update custom entry point to not use SPI symbols --- Documentation/CMake.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Documentation/CMake.md b/Documentation/CMake.md index 34cbf668c..cb1c88332 100644 --- a/Documentation/CMake.md +++ b/Documentation/CMake.md @@ -59,18 +59,24 @@ endif() ## Add an entry point You must include a source file in your test executable target with a -`@main` entry point. +`@main` entry point. The example main below requires the experimental +`Extern` feature. The declaration of `swt_abiv0_getEntryPoint` could +also be written in a C header file with its own `module.modulemap`. ```swift -import Foundation -@_spi(ForToolsIntegrationOnly) import Testing +typealias EntryPoint = @convention(thin) @Sendable (_ configurationJSON: UnsafeRawBufferPointer?, _ recordHandler: @escaping @Sendable (_ recordJSON: UnsafeRawBufferPointer) -> Void) async throws -> Bool + +@_extern(c, "swt_abiv0_getEntryPoint") +func swt_abiv0_getEntryPoint() -> UnsafeRawPointer @main struct Runner { static func main() async throws { - let configurationJSON: UnsafeRawBufferPointer? = nil + nonisolated(unsafe) let configurationJSON: UnsafeRawBufferPointer? = nil let recordHandler: @Sendable (UnsafeRawBufferPointer) -> Void = { _ in } - if try await ABIv0.entryPoint(configurationJSON, recordHandler) { + let entryPoint = unsafeBitCast(swt_abiv0_getEntryPoint(), to: EntryPoint.self) + + if try await entryPoint(configurationJSON, recordHandler) { exit(EXIT_SUCCESS) } else { exit(EXIT_FAILURE) From c6af86b1422eecc115131111cd875dde77eccb85 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Tue, 10 Dec 2024 11:49:40 -0700 Subject: [PATCH 3/4] Don't forget to import Foundation for exit() --- Documentation/CMake.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/CMake.md b/Documentation/CMake.md index cb1c88332..a90904205 100644 --- a/Documentation/CMake.md +++ b/Documentation/CMake.md @@ -64,6 +64,8 @@ You must include a source file in your test executable target with a also be written in a C header file with its own `module.modulemap`. ```swift +import Foundation + typealias EntryPoint = @convention(thin) @Sendable (_ configurationJSON: UnsafeRawBufferPointer?, _ recordHandler: @escaping @Sendable (_ recordJSON: UnsafeRawBufferPointer) -> Void) async throws -> Bool @_extern(c, "swt_abiv0_getEntryPoint") From 5dfdad40f2ce69a0e77d9b081553e1efa74efdf4 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Wed, 11 Dec 2024 18:05:06 -0700 Subject: [PATCH 4/4] Revert "Don't forget to import Foundation for exit()" This reverts commit c6af86b1422eecc115131111cd875dde77eccb85. --- Documentation/CMake.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/Documentation/CMake.md b/Documentation/CMake.md index a90904205..cb1c88332 100644 --- a/Documentation/CMake.md +++ b/Documentation/CMake.md @@ -64,8 +64,6 @@ You must include a source file in your test executable target with a also be written in a C header file with its own `module.modulemap`. ```swift -import Foundation - typealias EntryPoint = @convention(thin) @Sendable (_ configurationJSON: UnsafeRawBufferPointer?, _ recordHandler: @escaping @Sendable (_ recordJSON: UnsafeRawBufferPointer) -> Void) async throws -> Bool @_extern(c, "swt_abiv0_getEntryPoint")