Skip to content

Commit 7dfb5e8

Browse files
committed
Attempt to work around Amazon Linux crash
1 parent 1cffffd commit 7dfb5e8

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

Sources/Build/LLBuildCommands.swift

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ final class TestEntryPointCommand: CustomLLBuildCommand, TestBuildCommand {
233233
"false"
234234
}
235235

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+
236243
stream.send(
237244
#"""
238245
#if \#(swiftTestingImportCondition)
@@ -262,24 +269,37 @@ final class TestEntryPointCommand: CustomLLBuildCommand, TestBuildCommand {
262269
return "xctest"
263270
}
264271
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) {
266279
let testingLibrary = Self.testingLibrary()
267-
#if \#(swiftTestingImportCondition)
280+
#if \#(swiftTestingImportCondition)
268281
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
269288
await Testing.__swiftPMEntryPoint() as Never
289+
#endif
270290
}
271-
#endif
272-
#if \#(xctestImportCondition)
291+
#endif
292+
#if \#(xctestImportCondition)
273293
if testingLibrary == "xctest" {
274294
\#(testObservabilitySetup)
275-
#if os(WASI)
295+
#if os(WASI)
276296
/// On WASI, we can't block the main thread, so XCTestMain is defined as async.
277297
await XCTMain(__allDiscoveredTests()) as Never
278-
#else
298+
#else
279299
XCTMain(__allDiscoveredTests()) as Never
280-
#endif
300+
#endif
281301
}
282-
#endif
302+
#endif
283303
}
284304
}
285305
"""#

0 commit comments

Comments
 (0)