@@ -17,18 +17,6 @@ import Foundation
1717import PackagePlugin
1818import Synchronization
1919
20- #if os(macOS)
21- import Darwin
22- #elseif canImport(Glibc)
23- import Glibc
24- #elseif canImport(Musl)
25- import Musl
26- #elseif os(Windows)
27- import ucrt
28- #else
29- #error("Unsupported platform")
30- #endif
31-
3220@available ( macOS 15 . 0 , * )
3321@main
3422struct AWSLambdaPackager : CommandPlugin {
@@ -284,9 +272,22 @@ struct AWSLambdaPackager: CommandPlugin {
284272 print ( " \( executable. string) \( arguments. joined ( separator: " " ) ) " )
285273 }
286274
275+ let fd = dup ( 1 )
276+ let stdout = fdopen ( fd, " rw " ) !
277+ defer { fclose ( stdout) }
278+
279+ // We need to use an unsafe transfer here to get the fd into our Sendable closure.
280+ // This transfer is fine, because we guarantee that the code in the outputHandler
281+ // is run before we continue the functions execution, where the fd is used again.
282+ // See `process.waitUntilExit()` and the following `outputSync.wait()`
283+ struct UnsafeTransfer < Value> : @unchecked Sendable {
284+ let value : Value
285+ }
286+
287287 let outputMutex = Mutex ( " " )
288288 let outputSync = DispatchGroup ( )
289289 let outputQueue = DispatchQueue ( label: " AWSLambdaPackager.output " )
290+ let unsafeTransfer = UnsafeTransfer ( value: stdout)
290291 let outputHandler = { @Sendable ( data: Data? ) in
291292 dispatchPrecondition ( condition: . onQueue( outputQueue) )
292293
@@ -311,7 +312,7 @@ struct AWSLambdaPackager: CommandPlugin {
311312 case . debug( let outputIndent) , . output( let outputIndent) :
312313 print ( String ( repeating: " " , count: outputIndent) , terminator: " " )
313314 print ( _output)
314- fflush ( stdout )
315+ fflush ( unsafeTransfer . value )
315316 }
316317 }
317318
0 commit comments