Skip to content

Commit 1d96372

Browse files
authored
Moved Foundation to AWSLambdaRuntime; AWSLambdaRuntime renamed to AWSLambdaRuntimeCore (#41)
motivation: enable non-foundation module for performance sensitive use cases changes: * rename AWSLambdaRuntime to AWSLambdaRuntimeCore * create AWSLambdaRuntime for Foundation dependent functionality * have (new) AWSLambdaRuntime export AWSLambdaRuntimeCore * adjust tests
1 parent 29d6317 commit 1d96372

23 files changed

+105
-262
lines changed

Package.swift

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ let package = Package(
88
.macOS(.v10_13),
99
],
1010
products: [
11-
// core library
11+
// this library exports `AWSLambdaRuntimeCore` and adds Foundation convenience methods
1212
.library(name: "AWSLambdaRuntime", targets: ["AWSLambdaRuntime"]),
13+
// this has all the main functionality for lambda and it does not link Foundation
14+
.library(name: "AWSLambdaRuntimeCore", targets: ["AWSLambdaRuntimeCore"]),
1315
// common AWS events
1416
.library(name: "AWSLambdaEvents", targets: ["AWSLambdaEvents"]),
1517
// for testing only
@@ -22,23 +24,40 @@ let package = Package(
2224
],
2325
targets: [
2426
.target(name: "AWSLambdaRuntime", dependencies: [
27+
.byName(name: "AWSLambdaRuntimeCore"),
28+
.product(name: "NIO", package: "swift-nio"),
29+
.product(name: "NIOFoundationCompat", package: "swift-nio"),
30+
]),
31+
.target(name: "AWSLambdaRuntimeCore", dependencies: [
2532
.product(name: "Logging", package: "swift-log"),
2633
.product(name: "Backtrace", package: "swift-backtrace"),
2734
.product(name: "NIOHTTP1", package: "swift-nio"),
28-
.product(name: "NIOFoundationCompat", package: "swift-nio"),
2935
]),
30-
.testTarget(name: "AWSLambdaRuntimeTests", dependencies: ["AWSLambdaRuntime"]),
36+
.testTarget(name: "AWSLambdaRuntimeCoreTests", dependencies: [
37+
.byName(name: "AWSLambdaRuntimeCore"),
38+
]),
39+
.testTarget(name: "AWSLambdaRuntimeTests", dependencies: [
40+
.byName(name: "AWSLambdaRuntimeCore"),
41+
.byName(name: "AWSLambdaRuntime"),
42+
]),
3143
.target(name: "AWSLambdaEvents", dependencies: []),
3244
.testTarget(name: "AWSLambdaEventsTests", dependencies: ["AWSLambdaEvents"]),
3345
// testing helper
3446
.target(name: "AWSLambdaTesting", dependencies: [
35-
"AWSLambdaRuntime",
47+
.byName(name: "AWSLambdaRuntime"),
3648
.product(name: "NIO", package: "swift-nio"),
3749
]),
38-
.testTarget(name: "AWSLambdaTestingTests", dependencies: ["AWSLambdaTesting"]),
50+
.testTarget(name: "AWSLambdaTestingTests", dependencies: [
51+
.byName(name: "AWSLambdaTesting"),
52+
.byName(name: "AWSLambdaRuntime"),
53+
]),
3954
// samples
40-
.target(name: "StringSample", dependencies: ["AWSLambdaRuntime"]),
41-
.target(name: "CodableSample", dependencies: ["AWSLambdaRuntime"]),
55+
.target(name: "StringSample", dependencies: [
56+
.byName(name: "AWSLambdaRuntime"),
57+
]),
58+
.target(name: "CodableSample", dependencies: [
59+
.byName(name: "AWSLambdaRuntime"),
60+
]),
4261
// perf tests
4362
.target(name: "MockServer", dependencies: [
4463
.product(name: "NIOHTTP1", package: "swift-nio"),
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftAWSLambdaRuntime open source project
4+
//
5+
// Copyright (c) 2017-2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import AWSLambdaRuntimeCore
16+
import struct Foundation.Date
17+
18+
extension Lambda.Context {
19+
var deadlineDate: Date {
20+
let secondsSinceEpoch = Double(Int64(bitPattern: self.deadline.rawValue)) / -1_000_000_000
21+
return Date(timeIntervalSince1970: secondsSinceEpoch)
22+
}
23+
}

Sources/AWSLambdaRuntime/Lambda+Codable.swift

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the SwiftAWSLambdaRuntime open source project
44
//
5-
// Copyright (c) 2017-2018 Apple Inc. and the SwiftAWSLambdaRuntime project authors
5+
// Copyright (c) 2017-2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -12,6 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
@_exported import AWSLambdaRuntimeCore
1516
import class Foundation.JSONDecoder
1617
import class Foundation.JSONEncoder
1718
import NIO
@@ -29,7 +30,7 @@ extension Lambda {
2930
///
3031
/// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
3132
public static func run<In: Decodable, Out: Encodable>(_ closure: @escaping CodableClosure<In, Out>) {
32-
self.run(closure: closure)
33+
self.run(CodableClosureWrapper(closure))
3334
}
3435

3536
/// An asynchronous Lambda Closure that takes a `In: Decodable` and returns a `Result<Void, Error>` via a completion handler.
@@ -42,19 +43,7 @@ extension Lambda {
4243
///
4344
/// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
4445
public static func run<In: Decodable>(_ closure: @escaping CodableVoidClosure<In>) {
45-
self.run(closure: closure)
46-
}
47-
48-
// for testing
49-
@discardableResult
50-
internal static func run<In: Decodable, Out: Encodable>(configuration: Configuration = .init(), closure: @escaping CodableClosure<In, Out>) -> Result<Int, Error> {
51-
self.run(configuration: configuration, handler: CodableClosureWrapper(closure))
52-
}
53-
54-
// for testing
55-
@discardableResult
56-
internal static func run<In: Decodable>(configuration: Configuration = .init(), closure: @escaping CodableVoidClosure<In>) -> Result<Int, Error> {
57-
self.run(configuration: configuration, handler: CodableVoidClosureWrapper(closure))
46+
self.run(CodableVoidClosureWrapper(closure))
5847
}
5948
}
6049

Sources/AWSLambdaTesting/Lambda+Testing.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// @testable is used to access of internal functions
1818
#if DEBUG
1919
@testable import AWSLambdaRuntime
20+
@testable import AWSLambdaRuntimeCore
2021
import Dispatch
2122
import Logging
2223
import NIO

Sources/CodableSample/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the SwiftAWSLambdaRuntime open source project
44
//
5-
// Copyright (c) 2017-2018 Apple Inc. and the SwiftAWSLambdaRuntime project authors
5+
// Copyright (c) 2017-2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information

Sources/StringSample/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import AWSLambdaRuntime
15+
import AWSLambdaRuntimeCore
1616
import NIO
1717

1818
// in this example we are receiving and responding with strings

Tests/AWSLambdaRuntimeTests/Lambda+StringTest.swift renamed to Tests/AWSLambdaRuntimeCoreTests/Lambda+StringTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
@testable import AWSLambdaRuntime
15+
@testable import AWSLambdaRuntimeCore
1616
import NIO
1717
import XCTest
1818

Tests/AWSLambdaRuntimeTests/LambdaRunnerTest.swift renamed to Tests/AWSLambdaRuntimeCoreTests/LambdaRunnerTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
@testable import AWSLambdaRuntime
15+
@testable import AWSLambdaRuntimeCore
1616
import XCTest
1717

1818
class LambdaRunnerTest: XCTestCase {

Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTest.swift renamed to Tests/AWSLambdaRuntimeCoreTests/LambdaRuntimeClientTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
@testable import AWSLambdaRuntime
15+
@testable import AWSLambdaRuntimeCore
1616
import XCTest
1717

1818
class LambdaRuntimeClientTest: XCTestCase {

Tests/AWSLambdaRuntimeTests/LambdaTest.swift renamed to Tests/AWSLambdaRuntimeCoreTests/LambdaTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
@testable import AWSLambdaRuntime
15+
@testable import AWSLambdaRuntimeCore
1616
import Logging
1717
import NIO
1818
import XCTest

Tests/AWSLambdaRuntimeTests/MockLambdaServer.swift renamed to Tests/AWSLambdaRuntimeCoreTests/MockLambdaServer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
@testable import AWSLambdaRuntime
15+
@testable import AWSLambdaRuntimeCore
1616
import Foundation // for JSON
1717
import Logging
1818
import NIO

Tests/AWSLambdaRuntimeTests/Utils.swift renamed to Tests/AWSLambdaRuntimeCoreTests/Utils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
@testable import AWSLambdaRuntime
15+
@testable import AWSLambdaRuntimeCore
1616
import Logging
1717
import NIO
1818
import XCTest

0 commit comments

Comments
 (0)