Skip to content

Commit be37729

Browse files
committed
Fix errors
1 parent fa0dfa0 commit be37729

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

Package.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
import PackageDescription
44

5+
#if os(macOS)
6+
let platforms: [PackageDescription.SupportedPlatform]? = [.macOS(.v15)]
7+
#else
8+
let platforms: [PackageDescription.SupportedPlatform]? = nil
9+
#endif
10+
511
let package = Package(
612
name: "swift-aws-lambda-runtime",
7-
platforms: [
8-
.macOS(.v15)
9-
],
13+
platforms: platforms,
1014
products: [
1115
// this library exports `AWSLambdaRuntimeCore` and adds Foundation convenience methods
1216
.library(name: "AWSLambdaRuntime", targets: ["AWSLambdaRuntime"]),
@@ -21,7 +25,7 @@ let package = Package(
2125
dependencies: [
2226
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.67.0")),
2327
.package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.5.4")),
24-
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
28+
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"),
2529
],
2630
targets: [
2731
.target(

Plugins/AWSLambdaPackager/Plugin.swift

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@ import Foundation
1717
import PackagePlugin
1818
import 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
3422
struct 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

Comments
 (0)