Skip to content

Commit 21e224e

Browse files
authored
Update local server for Swift 6 compliance (#428)
* Update local server to Swift 6 * fix compilation error for local server in release mode * [CI] fix error for integration plugin test
1 parent 8724c47 commit 21e224e

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

.github/workflows/integration_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ jobs:
114114
pushd Examples/${EXAMPLE}
115115
116116
# package the example (docker and swift toolchain are installed on the GH runner)
117-
echo yes | swift package archive --allow-network-connections docker
117+
LAMBDA_USE_LOCAL_DEPS=../.. swift package archive --allow-network-connections docker
118118
119119
# did the plugin generated a Linux binary?
120120
[ -f ${OUTPUT_FILE} ]

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let package = Package(
2323
.library(name: "AWSLambdaTesting", targets: ["AWSLambdaTesting"]),
2424
],
2525
dependencies: [
26-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.72.0"),
26+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.76.0"),
2727
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
2828
],
2929
targets: [

Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
// commented out as long as we have a fix for Swift 6 language mode CI
16-
1715
#if DEBUG
1816
import Dispatch
1917
import Logging
@@ -133,6 +131,10 @@ private enum LocalLambda {
133131
}
134132

135133
func processRequest(context: ChannelHandlerContext, request: (head: HTTPRequestHead, body: ByteBuffer?)) {
134+
135+
let eventLoop = context.eventLoop
136+
let loopBoundContext = NIOLoopBound(context, eventLoop: eventLoop)
137+
136138
switch (request.head.method, request.head.uri) {
137139
// this endpoint is called by the client invoking the lambda
138140
case (.POST, let url) where url.hasSuffix(self.invocationEndpoint):
@@ -142,6 +144,7 @@ private enum LocalLambda {
142144
let requestID = "\(DispatchTime.now().uptimeNanoseconds)" // FIXME:
143145
let promise = context.eventLoop.makePromise(of: Response.self)
144146
promise.futureResult.whenComplete { result in
147+
let context = loopBoundContext.value
145148
switch result {
146149
case .failure(let error):
147150
self.logger.error("invocation error: \(error)")
@@ -178,6 +181,7 @@ private enum LocalLambda {
178181
// create a promise that we can fullfill when we get a new task
179182
let promise = context.eventLoop.makePromise(of: Invocation.self)
180183
promise.futureResult.whenComplete { result in
184+
let context = loopBoundContext.value
181185
switch result {
182186
case .failure(let error):
183187
self.logger.error("invocation error: \(error)")

Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
7676

7777
} else {
7878

79-
// we're not running on Lambda, let's start a local server for testing
79+
#if DEBUG
80+
// we're not running on Lambda and we're compiled in DEBUG mode,
81+
// let's start a local server for testing
8082
try await Lambda.withLocalServer(invocationEndpoint: Lambda.env("LOCAL_LAMBDA_SERVER_INVOCATION_ENDPOINT"))
8183
{
8284

@@ -92,6 +94,10 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
9294
)
9395
}
9496
}
97+
#else
98+
// in release mode, we can't start a local server because the local server code is not compiled.
99+
throw LambdaRuntimeError(code: .missingLambdaRuntimeAPIEnvironmentVariable)
100+
#endif
95101
}
96102
}
97103
}

0 commit comments

Comments
 (0)