Skip to content

Commit f329874

Browse files
authored
Require Swift 6 (#341)
* Require Swift 6 * Apply formatter * Disable 5.8, 5.9, and 5.10 checks * Remove -warnings-as-errors for now * Ensure plugin compiles in Swift 6 language mode
1 parent ab8166a commit f329874

File tree

4 files changed

+56
-128
lines changed

4 files changed

+56
-128
lines changed

.github/workflows/pull_request.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ jobs:
1616
name: Unit tests
1717
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
1818
with:
19-
linux_5_8_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
20-
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
21-
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
22-
linux_nightly_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
23-
linux_nightly_main_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
19+
linux_5_8_enabled: false
20+
linux_5_9_enabled: false
21+
linux_5_10_enabled: false
22+
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
23+
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
2424

2525
swift-6-language-mode:
2626
name: Swift 6 Language Mode

Package.swift

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:6.0
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(.v12),
9-
.iOS(.v15),
10-
.tvOS(.v15),
11-
.watchOS(.v8),
12-
],
13+
platforms: platforms,
1314
products: [
1415
// this library exports `AWSLambdaRuntimeCore` and adds Foundation convenience methods
1516
.library(name: "AWSLambdaRuntime", targets: ["AWSLambdaRuntime"]),
1617
// this has all the main functionality for lambda and it does not link Foundation
1718
.library(name: "AWSLambdaRuntimeCore", targets: ["AWSLambdaRuntimeCore"]),
1819
// plugin to package the lambda, creating an archive that can be uploaded to AWS
20+
// requires Linux or at least macOS v15
1921
.plugin(name: "AWSLambdaPackager", targets: ["AWSLambdaPackager"]),
2022
// for testing only
2123
.library(name: "AWSLambdaTesting", targets: ["AWSLambdaTesting"]),
2224
],
2325
dependencies: [
2426
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.67.0")),
2527
.package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.5.4")),
26-
.package(url: "https://github.com/apple/swift-docc-plugin", exact: "1.3.0"),
28+
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"),
2729
],
2830
targets: [
2931
.target(
@@ -32,7 +34,8 @@ let package = Package(
3234
.byName(name: "AWSLambdaRuntimeCore"),
3335
.product(name: "NIOCore", package: "swift-nio"),
3436
.product(name: "NIOFoundationCompat", package: "swift-nio"),
35-
]
37+
],
38+
swiftSettings: [.swiftLanguageMode(.v5)]
3639
),
3740
.target(
3841
name: "AWSLambdaRuntimeCore",
@@ -42,7 +45,8 @@ let package = Package(
4245
.product(name: "NIOCore", package: "swift-nio"),
4346
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
4447
.product(name: "NIOPosix", package: "swift-nio"),
45-
]
48+
],
49+
swiftSettings: [.swiftLanguageMode(.v5)]
4650
),
4751
.plugin(
4852
name: "AWSLambdaPackager",
@@ -60,31 +64,39 @@ let package = Package(
6064
.byName(name: "AWSLambdaRuntimeCore"),
6165
.product(name: "NIOTestUtils", package: "swift-nio"),
6266
.product(name: "NIOFoundationCompat", package: "swift-nio"),
63-
]
67+
],
68+
swiftSettings: [.swiftLanguageMode(.v5)]
6469
),
6570
.testTarget(
6671
name: "AWSLambdaRuntimeTests",
6772
dependencies: [
6873
.byName(name: "AWSLambdaRuntimeCore"),
6974
.byName(name: "AWSLambdaRuntime"),
70-
]
75+
],
76+
swiftSettings: [.swiftLanguageMode(.v5)]
7177
),
7278
// testing helper
7379
.target(
7480
name: "AWSLambdaTesting",
7581
dependencies: [
7682
.byName(name: "AWSLambdaRuntime"),
7783
.product(name: "NIO", package: "swift-nio"),
78-
]
84+
],
85+
swiftSettings: [.swiftLanguageMode(.v5)]
86+
),
87+
.testTarget(
88+
name: "AWSLambdaTestingTests",
89+
dependencies: ["AWSLambdaTesting"],
90+
swiftSettings: [.swiftLanguageMode(.v5)]
7991
),
80-
.testTarget(name: "AWSLambdaTestingTests", dependencies: ["AWSLambdaTesting"]),
8192
// for perf testing
8293
.executableTarget(
8394
name: "MockServer",
8495
dependencies: [
8596
.product(name: "NIOHTTP1", package: "swift-nio"),
8697
.product(name: "NIO", package: "swift-nio"),
87-
]
98+
],
99+
swiftSettings: [.swiftLanguageMode(.v5)]
88100
),
89101
]
90102
)

[email protected]

Lines changed: 0 additions & 92 deletions
This file was deleted.

Plugins/AWSLambdaPackager/Plugin.swift

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,9 @@
1515
import Dispatch
1616
import Foundation
1717
import PackagePlugin
18+
import Synchronization
1819

19-
#if os(macOS)
20-
import Darwin
21-
#elseif canImport(Glibc)
22-
import Glibc
23-
#elseif canImport(Musl)
24-
import Musl
25-
#elseif os(Windows)
26-
import ucrt
27-
#else
28-
#error("Unsupported platform")
29-
#endif
30-
20+
@available(macOS 15.0, *)
3121
@main
3222
struct AWSLambdaPackager: CommandPlugin {
3323
func performCommand(context: PackagePlugin.PluginContext, arguments: [String]) async throws {
@@ -282,10 +272,23 @@ struct AWSLambdaPackager: CommandPlugin {
282272
print("\(executable.string) \(arguments.joined(separator: " "))")
283273
}
284274

285-
var output = ""
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+
let outputMutex = Mutex("")
286288
let outputSync = DispatchGroup()
287289
let outputQueue = DispatchQueue(label: "AWSLambdaPackager.output")
288-
let outputHandler = { (data: Data?) in
290+
let unsafeTransfer = UnsafeTransfer(value: stdout)
291+
let outputHandler = { @Sendable (data: Data?) in
289292
dispatchPrecondition(condition: .onQueue(outputQueue))
290293

291294
outputSync.enter()
@@ -299,15 +302,17 @@ struct AWSLambdaPackager: CommandPlugin {
299302
return
300303
}
301304

302-
output += _output + "\n"
305+
outputMutex.withLock { output in
306+
output += _output + "\n"
307+
}
303308

304309
switch logLevel {
305310
case .silent:
306311
break
307312
case .debug(let outputIndent), .output(let outputIndent):
308313
print(String(repeating: " ", count: outputIndent), terminator: "")
309314
print(_output)
310-
fflush(stdout)
315+
fflush(unsafeTransfer.value)
311316
}
312317
}
313318

@@ -336,6 +341,8 @@ struct AWSLambdaPackager: CommandPlugin {
336341
// wait for output to be full processed
337342
outputSync.wait()
338343

344+
let output = outputMutex.withLock { $0 }
345+
339346
if process.terminationStatus != 0 {
340347
// print output on failure and if not already printed
341348
if logLevel < .output {
@@ -359,6 +366,7 @@ struct AWSLambdaPackager: CommandPlugin {
359366
}
360367
}
361368

369+
@available(macOS 15.0, *)
362370
private struct Configuration: CustomStringConvertible {
363371
public let outputDirectory: Path
364372
public let products: [Product]

0 commit comments

Comments
 (0)