From 5cd77e7eff2dcb1383603f36f6a940134a039d1c Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sun, 17 Nov 2024 15:36:49 -0700 Subject: [PATCH 1/6] 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/6] 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/6] 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/6] 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") From 6a8c923450ec771355384f89237edd2935ddc3aa Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Mon, 12 May 2025 10:24:39 -0600 Subject: [PATCH 5/6] Documentation: Reword options for getting entry point addr --- Documentation/CMake.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Documentation/CMake.md b/Documentation/CMake.md index cb1c88332..b0d59e2e4 100644 --- a/Documentation/CMake.md +++ b/Documentation/CMake.md @@ -60,8 +60,12 @@ endif() You must include a source file in your test executable target with a `@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`. +`Extern` feature. The function `swt_abiv0_getEntryPoint` is exported +from the swift-testing dylib. As such, its declaration could instead +be written in a C header file with its own `module.modulemap`, or +the runtime address could be obtained via +[`dlsym()`](https://man7.org/linux/man-pages/man3/dlsym.3.html) or +[`GetProcAddress()`](https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getprocaddress). ```swift typealias EntryPoint = @convention(thin) @Sendable (_ configurationJSON: UnsafeRawBufferPointer?, _ recordHandler: @escaping @Sendable (_ recordJSON: UnsafeRawBufferPointer) -> Void) async throws -> Bool @@ -86,7 +90,7 @@ func swt_abiv0_getEntryPoint() -> UnsafeRawPointer ``` For more information on the input configuration and output records of the ABI entry -point, refer to the [ABI documentation](ABI/JSON.md) +point, refer to the [ABI documentation](ABI/JSON.md). ## Integrate with CTest From 8b47c1f7ce5674656f7f3cc2f2475ef819405685 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Mon, 12 May 2025 10:29:39 -0600 Subject: [PATCH 6/6] Reference POSIX instead of man7.org --- Documentation/CMake.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/CMake.md b/Documentation/CMake.md index b0d59e2e4..37b9e1d4e 100644 --- a/Documentation/CMake.md +++ b/Documentation/CMake.md @@ -64,7 +64,7 @@ You must include a source file in your test executable target with a from the swift-testing dylib. As such, its declaration could instead be written in a C header file with its own `module.modulemap`, or the runtime address could be obtained via -[`dlsym()`](https://man7.org/linux/man-pages/man3/dlsym.3.html) or +[`dlsym()`](https://pubs.opengroup.org/onlinepubs/9799919799/functions/dlsym.html) or [`GetProcAddress()`](https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getprocaddress). ```swift