@@ -17,18 +17,6 @@ import Foundation
17
17
import PackagePlugin
18
18
import Synchronization
19
19
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
-
32
20
@available ( macOS 15 . 0 , * )
33
21
@main
34
22
struct AWSLambdaPackager : CommandPlugin {
@@ -284,9 +272,22 @@ struct AWSLambdaPackager: CommandPlugin {
284
272
print ( " \( executable. string) \( arguments. joined ( separator: " " ) ) " )
285
273
}
286
274
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
+
287
287
let outputMutex = Mutex ( " " )
288
288
let outputSync = DispatchGroup ( )
289
289
let outputQueue = DispatchQueue ( label: " AWSLambdaPackager.output " )
290
+ let unsafeTransfer = UnsafeTransfer ( value: stdout)
290
291
let outputHandler = { @Sendable ( data: Data? ) in
291
292
dispatchPrecondition ( condition: . onQueue( outputQueue) )
292
293
@@ -311,7 +312,7 @@ struct AWSLambdaPackager: CommandPlugin {
311
312
case . debug( let outputIndent) , . output( let outputIndent) :
312
313
print ( String ( repeating: " " , count: outputIndent) , terminator: " " )
313
314
print ( _output)
314
- fflush ( stdout )
315
+ fflush ( unsafeTransfer . value )
315
316
}
316
317
}
317
318
0 commit comments