Skip to content

Commit e221dd8

Browse files
authored
remove swift-backtrace in swift >= 5.9 (swift-server#305)
motivation: swift 5.9 ships with builtin backtrace support \o/ changes: * remove the dependency on swift-backtrace when using swift 5.9 or above * conditionalize the call to Backtrace.install to relevant versions only
1 parent e7751d0 commit e221dd8

File tree

4 files changed

+151
-3
lines changed

4 files changed

+151
-3
lines changed

Package.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.7
1+
// swift-tools-version:5.9
22

33
import PackageDescription
44

@@ -23,7 +23,6 @@ let package = Package(
2323
dependencies: [
2424
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.43.1")),
2525
.package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.4.2")),
26-
.package(url: "https://github.com/swift-server/swift-backtrace.git", .upToNextMajor(from: "1.2.3")),
2726
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
2827
],
2928
targets: [
@@ -34,7 +33,6 @@ let package = Package(
3433
]),
3534
.target(name: "AWSLambdaRuntimeCore", dependencies: [
3635
.product(name: "Logging", package: "swift-log"),
37-
.product(name: "Backtrace", package: "swift-backtrace"),
3836
.product(name: "NIOHTTP1", package: "swift-nio"),
3937
.product(name: "NIOCore", package: "swift-nio"),
4038
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),

[email protected]

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// swift-tools-version:5.7
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "swift-aws-lambda-runtime",
7+
platforms: [
8+
.macOS(.v12),
9+
.iOS(.v15),
10+
.tvOS(.v15),
11+
.watchOS(.v8),
12+
],
13+
products: [
14+
// this library exports `AWSLambdaRuntimeCore` and adds Foundation convenience methods
15+
.library(name: "AWSLambdaRuntime", targets: ["AWSLambdaRuntime"]),
16+
// this has all the main functionality for lambda and it does not link Foundation
17+
.library(name: "AWSLambdaRuntimeCore", targets: ["AWSLambdaRuntimeCore"]),
18+
// plugin to package the lambda, creating an archive that can be uploaded to AWS
19+
.plugin(name: "AWSLambdaPackager", targets: ["AWSLambdaPackager"]),
20+
// for testing only
21+
.library(name: "AWSLambdaTesting", targets: ["AWSLambdaTesting"]),
22+
],
23+
dependencies: [
24+
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.43.1")),
25+
.package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.4.2")),
26+
.package(url: "https://github.com/swift-server/swift-backtrace.git", .upToNextMajor(from: "1.2.3")),
27+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
28+
],
29+
targets: [
30+
.target(name: "AWSLambdaRuntime", dependencies: [
31+
.byName(name: "AWSLambdaRuntimeCore"),
32+
.product(name: "NIOCore", package: "swift-nio"),
33+
.product(name: "NIOFoundationCompat", package: "swift-nio"),
34+
]),
35+
.target(name: "AWSLambdaRuntimeCore", dependencies: [
36+
.product(name: "Logging", package: "swift-log"),
37+
.product(name: "Backtrace", package: "swift-backtrace"),
38+
.product(name: "NIOHTTP1", package: "swift-nio"),
39+
.product(name: "NIOCore", package: "swift-nio"),
40+
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
41+
.product(name: "NIOPosix", package: "swift-nio"),
42+
]),
43+
.plugin(
44+
name: "AWSLambdaPackager",
45+
capability: .command(
46+
intent: .custom(
47+
verb: "archive",
48+
description: "Archive the Lambda binary and prepare it for uploading to AWS. Requires docker on macOS or non Amazonlinux 2 distributions."
49+
)
50+
)
51+
),
52+
.testTarget(name: "AWSLambdaRuntimeCoreTests", dependencies: [
53+
.byName(name: "AWSLambdaRuntimeCore"),
54+
.product(name: "NIOTestUtils", package: "swift-nio"),
55+
.product(name: "NIOFoundationCompat", package: "swift-nio"),
56+
]),
57+
.testTarget(name: "AWSLambdaRuntimeTests", dependencies: [
58+
.byName(name: "AWSLambdaRuntimeCore"),
59+
.byName(name: "AWSLambdaRuntime"),
60+
]),
61+
// testing helper
62+
.target(name: "AWSLambdaTesting", dependencies: [
63+
.byName(name: "AWSLambdaRuntime"),
64+
.product(name: "NIO", package: "swift-nio"),
65+
]),
66+
.testTarget(name: "AWSLambdaTestingTests", dependencies: ["AWSLambdaTesting"]),
67+
// for perf testing
68+
.executableTarget(name: "MockServer", dependencies: [
69+
.product(name: "NIOHTTP1", package: "swift-nio"),
70+
.product(name: "NIO", package: "swift-nio"),
71+
]),
72+
]
73+
)

[email protected]

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// swift-tools-version:5.7
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "swift-aws-lambda-runtime",
7+
platforms: [
8+
.macOS(.v12),
9+
.iOS(.v15),
10+
.tvOS(.v15),
11+
.watchOS(.v8),
12+
],
13+
products: [
14+
// this library exports `AWSLambdaRuntimeCore` and adds Foundation convenience methods
15+
.library(name: "AWSLambdaRuntime", targets: ["AWSLambdaRuntime"]),
16+
// this has all the main functionality for lambda and it does not link Foundation
17+
.library(name: "AWSLambdaRuntimeCore", targets: ["AWSLambdaRuntimeCore"]),
18+
// plugin to package the lambda, creating an archive that can be uploaded to AWS
19+
.plugin(name: "AWSLambdaPackager", targets: ["AWSLambdaPackager"]),
20+
// for testing only
21+
.library(name: "AWSLambdaTesting", targets: ["AWSLambdaTesting"]),
22+
],
23+
dependencies: [
24+
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.43.1")),
25+
.package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.4.2")),
26+
.package(url: "https://github.com/swift-server/swift-backtrace.git", .upToNextMajor(from: "1.2.3")),
27+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
28+
],
29+
targets: [
30+
.target(name: "AWSLambdaRuntime", dependencies: [
31+
.byName(name: "AWSLambdaRuntimeCore"),
32+
.product(name: "NIOCore", package: "swift-nio"),
33+
.product(name: "NIOFoundationCompat", package: "swift-nio"),
34+
]),
35+
.target(name: "AWSLambdaRuntimeCore", dependencies: [
36+
.product(name: "Logging", package: "swift-log"),
37+
.product(name: "Backtrace", package: "swift-backtrace"),
38+
.product(name: "NIOHTTP1", package: "swift-nio"),
39+
.product(name: "NIOCore", package: "swift-nio"),
40+
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
41+
.product(name: "NIOPosix", package: "swift-nio"),
42+
]),
43+
.plugin(
44+
name: "AWSLambdaPackager",
45+
capability: .command(
46+
intent: .custom(
47+
verb: "archive",
48+
description: "Archive the Lambda binary and prepare it for uploading to AWS. Requires docker on macOS or non Amazonlinux 2 distributions."
49+
)
50+
)
51+
),
52+
.testTarget(name: "AWSLambdaRuntimeCoreTests", dependencies: [
53+
.byName(name: "AWSLambdaRuntimeCore"),
54+
.product(name: "NIOTestUtils", package: "swift-nio"),
55+
.product(name: "NIOFoundationCompat", package: "swift-nio"),
56+
]),
57+
.testTarget(name: "AWSLambdaRuntimeTests", dependencies: [
58+
.byName(name: "AWSLambdaRuntimeCore"),
59+
.byName(name: "AWSLambdaRuntime"),
60+
]),
61+
// testing helper
62+
.target(name: "AWSLambdaTesting", dependencies: [
63+
.byName(name: "AWSLambdaRuntime"),
64+
.product(name: "NIO", package: "swift-nio"),
65+
]),
66+
.testTarget(name: "AWSLambdaTestingTests", dependencies: ["AWSLambdaTesting"]),
67+
// for perf testing
68+
.executableTarget(name: "MockServer", dependencies: [
69+
.product(name: "NIOHTTP1", package: "swift-nio"),
70+
.product(name: "NIO", package: "swift-nio"),
71+
]),
72+
]
73+
)

Sources/AWSLambdaRuntimeCore/Lambda.swift

+4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import Glibc
1818
import Darwin.C
1919
#endif
2020

21+
#if swift(<5.9)
2122
import Backtrace
23+
#endif
2224
import Logging
2325
import NIOCore
2426
import NIOPosix
@@ -85,7 +87,9 @@ public enum Lambda {
8587
handlerType: (some ByteBufferLambdaHandler).Type
8688
) -> Result<Int, Error> {
8789
let _run = { (configuration: LambdaConfiguration) -> Result<Int, Error> in
90+
#if swift(<5.9)
8891
Backtrace.install()
92+
#endif
8993
var logger = Logger(label: "Lambda")
9094
logger.logLevel = configuration.general.logLevel
9195

0 commit comments

Comments
 (0)