@@ -233,6 +233,13 @@ final class TestEntryPointCommand: CustomLLBuildCommand, TestBuildCommand {
233
233
" false "
234
234
}
235
235
236
+ // FIXME: work around crash on Amazon Linux 2 when main function is async (rdar://128303921)
237
+ let asyncMainKeyword = if context. productsBuildParameters. triple. isLinux ( ) {
238
+ " async "
239
+ } else {
240
+ " "
241
+ }
242
+
236
243
stream. send (
237
244
#"""
238
245
#if \#( swiftTestingImportCondition)
@@ -262,24 +269,37 @@ final class TestEntryPointCommand: CustomLLBuildCommand, TestBuildCommand {
262
269
return "xctest"
263
270
}
264
271
265
- static func main() async {
272
+ #if os(Linux)
273
+ // FIXME: work around crash on Amazon Linux 2 when main function is async (rdar://128303921)
274
+ @_silgen_name("$ss13_runAsyncMainyyyyYaKcF")
275
+ private static func _runAsyncMain(_ asyncFun: @Sendable @escaping () async throws -> ())
276
+ #endif
277
+
278
+ static func main() \(asyncMainKeyword) {
266
279
let testingLibrary = Self.testingLibrary()
267
- #if \#( swiftTestingImportCondition)
280
+ #if \#( swiftTestingImportCondition)
268
281
if testingLibrary == "swift-testing" {
282
+ #if os(Linux)
283
+ // FIXME: work around crash on Amazon Linux 2 when main function is async (rdar://128303921)
284
+ _runAsyncMain {
285
+ await Testing.__swiftPMEntryPoint() as Never
286
+ }
287
+ #else
269
288
await Testing.__swiftPMEntryPoint() as Never
289
+ #endif
270
290
}
271
- #endif
272
- #if \#( xctestImportCondition)
291
+ #endif
292
+ #if \#( xctestImportCondition)
273
293
if testingLibrary == "xctest" {
274
294
\#( testObservabilitySetup)
275
- #if os(WASI)
295
+ #if os(WASI)
276
296
/// On WASI, we can't block the main thread, so XCTestMain is defined as async.
277
297
await XCTMain(__allDiscoveredTests()) as Never
278
- #else
298
+ #else
279
299
XCTMain(__allDiscoveredTests()) as Never
280
- #endif
300
+ #endif
281
301
}
282
- #endif
302
+ #endif
283
303
}
284
304
}
285
305
"""#
0 commit comments