Skip to content

Commit 4b2b32d

Browse files
authored
Merge branch 'main' into sebsto/fix_507
2 parents fa0fd88 + 41c5eda commit 4b2b32d

12 files changed

+72
-39
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,13 @@ jobs:
1717
format_check_container_image: "swiftlang/swift:nightly-6.1-jammy"
1818
yamllint_check_enabled: true
1919

20-
# https://github.com/apple/swift-nio/blob/main/.github/workflows/unit_tests.yml
2120
unit-tests:
2221
name: Unit tests
2322
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
2423
with:
2524
linux_5_9_enabled: false
2625
linux_5_10_enabled: false
27-
linux_6_0_enabled: true
28-
# this currently resolves to 6.1 nightly
29-
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error"
30-
linux_nightly_next_enabled: true
31-
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error"
32-
# this currently resolves to 6.2.dev
33-
# It crashes some of our tests https://github.com/swift-server/swift-aws-lambda-runtime/issues/509
34-
linux_nightly_main_enabled: true
26+
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
3527
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
3628

3729
integration-tests:

Examples/CDK/infra/package-lock.json

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/CDK/infra/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"typescript": "~5.8.2"
1818
},
1919
"dependencies": {
20-
"aws-cdk-lib": "^2.183.0",
20+
"aws-cdk-lib": "^2.189.1",
2121
"constructs": "^10.4.2"
2222
}
2323
}

Sources/AWSLambdaRuntime/ControlPlaneRequest.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@ enum ControlPlaneResponse: Hashable {
2828
case error(ErrorResponse)
2929
}
3030

31-
package struct InvocationMetadata: Hashable {
31+
@usableFromInline
32+
package struct InvocationMetadata: Hashable, Sendable {
33+
@usableFromInline
3234
package let requestID: String
35+
@usableFromInline
3336
package let deadlineInMillisSinceEpoch: Int64
37+
@usableFromInline
3438
package let invokedFunctionARN: String
39+
@usableFromInline
3540
package let traceID: String
41+
@usableFromInline
3642
package let clientContext: String?
43+
@usableFromInline
3744
package let cognitoIdentity: String?
3845

3946
package init(headers: HTTPHeaders) throws(LambdaRuntimeError) {

Sources/AWSLambdaRuntime/Lambda+LocalServer.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extension Lambda {
4545
/// - body: Code to run within the context of the mock server. Typically this would be a Lambda.run function call.
4646
///
4747
/// - note: This API is designed strictly for local testing and is behind a DEBUG flag
48+
@usableFromInline
4849
static func withLocalServer(
4950
invocationEndpoint: String? = nil,
5051
_ body: sending @escaping () async throws -> Void
@@ -237,7 +238,7 @@ private struct LambdaHTTPServer {
237238
requestHead = head
238239

239240
case .body(let body):
240-
requestBody = body
241+
requestBody.setOrWriteImmutableBuffer(body)
241242

242243
case .end:
243244
precondition(requestHead != nil, "Received .end without .head")

Sources/AWSLambdaRuntime/Lambda.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import ucrt
3030
#endif
3131

3232
public enum Lambda {
33+
@inlinable
3334
package static func runLoop<RuntimeClient: LambdaRuntimeClientProtocol, Handler>(
3435
runtimeClient: RuntimeClient,
3536
handler: Handler,

Sources/AWSLambdaRuntime/LambdaContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
8888
self.storage.logger
8989
}
9090

91-
init(
91+
public init(
9292
requestID: String,
9393
traceID: String,
9494
invokedFunctionARN: String,

Sources/AWSLambdaRuntime/LambdaRuntime.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ private let _isRunning = Atomic<Bool>(false)
3232
// sadly crashes the compiler today (on Linux).
3333
public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: StreamingLambdaHandler {
3434
// TODO: We want to change this to Mutex as soon as this doesn't crash the Swift compiler on Linux anymore
35+
@usableFromInline
3536
let handlerMutex: NIOLockedValueBox<Handler?>
37+
@usableFromInline
3638
let logger: Logger
39+
@usableFromInline
3740
let eventLoop: EventLoop
3841

3942
public init(
@@ -54,6 +57,7 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
5457
}
5558

5659
/// Make sure only one run() is called at a time
60+
@inlinable
5761
public func run() async throws {
5862

5963
// we use an atomic global variable to ensure only one LambdaRuntime is running at the time

Sources/AWSLambdaRuntime/LambdaRuntimeClient.swift

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,47 @@ import NIOCore
1717
import NIOHTTP1
1818
import NIOPosix
1919

20+
@usableFromInline
2021
final actor LambdaRuntimeClient: LambdaRuntimeClientProtocol {
22+
@usableFromInline
2123
nonisolated let unownedExecutor: UnownedSerialExecutor
2224

23-
struct Configuration {
25+
@usableFromInline
26+
struct Configuration: Sendable {
2427
var ip: String
2528
var port: Int
29+
30+
@usableFromInline
31+
init(ip: String, port: Int) {
32+
self.ip = ip
33+
self.port = port
34+
}
2635
}
2736

28-
struct Writer: LambdaRuntimeClientResponseStreamWriter {
37+
@usableFromInline
38+
struct Writer: LambdaRuntimeClientResponseStreamWriter, Sendable {
2939
private var runtimeClient: LambdaRuntimeClient
3040

3141
fileprivate init(runtimeClient: LambdaRuntimeClient) {
3242
self.runtimeClient = runtimeClient
3343
}
3444

45+
@usableFromInline
3546
func write(_ buffer: NIOCore.ByteBuffer) async throws {
3647
try await self.runtimeClient.write(buffer)
3748
}
3849

50+
@usableFromInline
3951
func finish() async throws {
4052
try await self.runtimeClient.writeAndFinish(nil)
4153
}
4254

55+
@usableFromInline
4356
func writeAndFinish(_ buffer: NIOCore.ByteBuffer) async throws {
4457
try await self.runtimeClient.writeAndFinish(buffer)
4558
}
4659

60+
@usableFromInline
4761
func reportError(_ error: any Error) async throws {
4862
try await self.runtimeClient.reportError(error)
4963
}
@@ -90,6 +104,7 @@ final actor LambdaRuntimeClient: LambdaRuntimeClientProtocol {
90104
// being fully closed before we can return from it.
91105
private var closingConnections: [any Channel] = []
92106

107+
@inlinable
93108
static func withRuntimeClient<Result>(
94109
configuration: Configuration,
95110
eventLoop: any EventLoop,
@@ -110,14 +125,16 @@ final actor LambdaRuntimeClient: LambdaRuntimeClientProtocol {
110125
return try result.get()
111126
}
112127

113-
private init(configuration: Configuration, eventLoop: any EventLoop, logger: Logger) {
128+
@usableFromInline
129+
init(configuration: Configuration, eventLoop: any EventLoop, logger: Logger) {
114130
self.unownedExecutor = eventLoop.executor.asUnownedSerialExecutor()
115131
self.configuration = configuration
116132
self.eventLoop = eventLoop
117133
self.logger = logger
118134
}
119135

120-
private func close() async {
136+
@usableFromInline
137+
func close() async {
121138
self.logger.trace("Close lambda runtime client")
122139

123140
guard case .notClosing = self.closingState else {
@@ -144,6 +161,7 @@ final actor LambdaRuntimeClient: LambdaRuntimeClientProtocol {
144161
}
145162
}
146163

164+
@usableFromInline
147165
func nextInvocation() async throws -> (Invocation, Writer) {
148166
try await withTaskCancellationHandler {
149167
switch self.lambdaState {

Sources/AWSLambdaRuntime/LambdaRuntimeClientProtocol.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,26 @@
1414

1515
import NIOCore
1616

17+
@usableFromInline
1718
package protocol LambdaRuntimeClientResponseStreamWriter: LambdaResponseStreamWriter {
1819
func write(_ buffer: ByteBuffer) async throws
1920
func finish() async throws
2021
func writeAndFinish(_ buffer: ByteBuffer) async throws
2122
func reportError(_ error: any Error) async throws
2223
}
2324

25+
@usableFromInline
2426
package protocol LambdaRuntimeClientProtocol {
2527
associatedtype Writer: LambdaRuntimeClientResponseStreamWriter
2628

2729
func nextInvocation() async throws -> (Invocation, Writer)
2830
}
2931

30-
package struct Invocation {
32+
@usableFromInline
33+
package struct Invocation: Sendable {
34+
@usableFromInline
3135
package var metadata: InvocationMetadata
36+
@usableFromInline
3237
package var event: ByteBuffer
3338

3439
package init(metadata: InvocationMetadata, event: ByteBuffer) {

Sources/AWSLambdaRuntime/LambdaRuntimeError.swift

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

15+
@usableFromInline
1516
public struct LambdaRuntimeError: Error {
17+
@usableFromInline
18+
/// internal error codes for LambdaRuntimeClient
1619
package enum Code: Sendable {
17-
18-
/// internal error codes for LambdaRuntimeClient
1920
case closingRuntimeClient
2021

2122
case connectionToControlPlaneLost
@@ -39,12 +40,15 @@ public struct LambdaRuntimeError: Error {
3940
case moreThanOneLambdaRuntimeInstance
4041
}
4142

43+
@usableFromInline
4244
package init(code: Code, underlying: (any Error)? = nil) {
4345
self.code = code
4446
self.underlying = underlying
4547
}
4648

47-
var code: Code
48-
public var underlying: (any Error)?
49+
@usableFromInline
50+
package var code: Code
51+
@usableFromInline
52+
package var underlying: (any Error)?
4953

5054
}

Sources/AWSLambdaRuntime/Utils.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ enum Signal: Int32 {
5959
}
6060

6161
extension DispatchWallTime {
62+
@usableFromInline
6263
init(millisSinceEpoch: Int64) {
6364
let nanoSinceEpoch = UInt64(millisSinceEpoch) * 1_000_000
6465
let seconds = UInt64(nanoSinceEpoch / 1_000_000_000)

0 commit comments

Comments
 (0)