Skip to content

Apply package traits #490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ on:
matrix_linux_swift_container_image:
type: string
description: "Container image for the matrix job. Defaults to matching latest Swift Ubuntu image."
default: "swift:amazonlinux2"
default: "swiftlang/swift:nightly-6.1-jammy"

## We are cancelling previously triggered workflow runs
concurrency:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
license_header_check_project_name: "SwiftAWSLambdaRuntime"
shell_check_enabled: true
python_lint_check_enabled: true
api_breakage_check_container_image: "swift:6.0-noble"
api_breakage_check_container_image: "swiftlang/swift:nightly-6.1-jammy"
docs_check_container_image: "swift:6.0-noble"
format_check_container_image: "swiftlang/swift:nightly-6.0-jammy"
format_check_container_image: "swiftlang/swift:nightly-6.1-jammy"
yamllint_check_enabled: true

unit-tests:
Expand Down
2 changes: 1 addition & 1 deletion .spi.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
builder:
configs:
- documentation_targets: [AWSLambdaRuntimeCore, AWSLambdaRuntime]
- documentation_targets: [AWSLambdaRuntime]
10 changes: 8 additions & 2 deletions Examples/HelloJSON/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:6.0
// swift-tools-version:6.1

import PackageDescription

Expand All @@ -13,7 +13,13 @@ let package = Package(
],
dependencies: [
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main")
.package(
url: "https://github.com/swift-server/swift-aws-lambda-runtime.git",
branch: "ff-package-traits",
traits: [
.trait(name: "FoundationJSONSupport")
]
)
],
targets: [
.executableTarget(
Expand Down
35 changes: 21 additions & 14 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,42 +1,50 @@
// swift-tools-version:6.0
// swift-tools-version:6.1

import PackageDescription

let package = Package(
name: "swift-aws-lambda-runtime",
platforms: [.macOS(.v15)],
products: [
// this library exports `AWSLambdaRuntimeCore` and adds Foundation convenience methods
.library(name: "AWSLambdaRuntime", targets: ["AWSLambdaRuntime"]),
// this has all the main functionality for lambda and it does not link Foundation
.library(name: "AWSLambdaRuntimeCore", targets: ["AWSLambdaRuntimeCore"]),
// plugin to package the lambda, creating an archive that can be uploaded to AWS
// requires Linux or at least macOS v15
.plugin(name: "AWSLambdaPackager", targets: ["AWSLambdaPackager"]),
// for testing only
.library(name: "AWSLambdaTesting", targets: ["AWSLambdaTesting"]),
],
traits: [
"FoundationJSONSupport",
"ServiceLifecycleSupport",
"LocalServerSupport",
.default(
Comment on lines +17 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I don't know if this needs the support suffix but not feeling too strongly

enabledTraits: [
"FoundationJSONSupport",
"ServiceLifecycleSupport",
"LocalServerSupport",
]
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.81.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
.package(url: "https://github.com/apple/swift-collections.git", from: "1.1.4"),
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.6.3"),
],
targets: [
.target(
name: "AWSLambdaRuntime",
dependencies: [
.byName(name: "AWSLambdaRuntimeCore"),
.product(name: "NIOCore", package: "swift-nio"),
]
),
.target(
name: "AWSLambdaRuntimeCore",
dependencies: [
.product(name: "DequeModule", package: "swift-collections"),
.product(name: "Logging", package: "swift-log"),
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOPosix", package: "swift-nio"),
.product(
name: "ServiceLifecycle",
package: "swift-service-lifecycle",
condition: .when(traits: ["ServiceLifecycleSupport"])
),
]
),
.plugin(
Expand All @@ -58,16 +66,15 @@ let package = Package(
.testTarget(
name: "AWSLambdaRuntimeCoreTests",
dependencies: [
.byName(name: "AWSLambdaRuntimeCore"),
.byName(name: "AWSLambdaRuntime"),
.product(name: "NIOTestUtils", package: "swift-nio"),
.product(name: "NIOFoundationCompat", package: "swift-nio"),
]
),
.testTarget(
name: "AWSLambdaRuntimeTests",
dependencies: [
.byName(name: "AWSLambdaRuntimeCore"),
.byName(name: "AWSLambdaRuntime"),
.byName(name: "AWSLambdaRuntime")
]
),
// testing helper
Expand Down
95 changes: 95 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// swift-tools-version:6.0

import PackageDescription

let package = Package(
name: "swift-aws-lambda-runtime",
platforms: [.macOS(.v15)],
products: [
.library(name: "AWSLambdaRuntime", targets: ["AWSLambdaRuntime"]),
// plugin to package the lambda, creating an archive that can be uploaded to AWS
// requires Linux or at least macOS v15
.plugin(name: "AWSLambdaPackager", targets: ["AWSLambdaPackager"]),
// for testing only
.library(name: "AWSLambdaTesting", targets: ["AWSLambdaTesting"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.81.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
.package(url: "https://github.com/apple/swift-collections.git", from: "1.1.4"),
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.6.3"),
],
targets: [
.target(
name: "AWSLambdaRuntime",
dependencies: [
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "DequeModule", package: "swift-collections"),
.product(name: "Logging", package: "swift-log"),
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "NIOPosix", package: "swift-nio"),
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
],
swiftSettings: [
.define("FoundationJSONSupport"),
.define("ServiceLifecycleSupport"),
.define("LocalServerSupport"),
]
),
.plugin(
name: "AWSLambdaPackager",
capability: .command(
intent: .custom(
verb: "archive",
description:
"Archive the Lambda binary and prepare it for uploading to AWS. Requires docker on macOS or non Amazonlinux 2 distributions."
),
permissions: [
.allowNetworkConnections(
scope: .docker,
reason: "This plugin uses Docker to create the AWS Lambda ZIP package."
)
]
)
),
.testTarget(
name: "AWSLambdaRuntimeCoreTests",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that AWSLambdaRuntimeCore doesn't exist, we should merge the tests too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this in a follow up to keep the changes as small as possible.

Copy link
Contributor

@sebsto sebsto Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, let be sure we file an issue to track this otherwise it might stay like this forever :-)

dependencies: [
.byName(name: "AWSLambdaRuntime"),
.product(name: "NIOTestUtils", package: "swift-nio"),
.product(name: "NIOFoundationCompat", package: "swift-nio"),
]
),
.testTarget(
name: "AWSLambdaRuntimeTests",
dependencies: [
.byName(name: "AWSLambdaRuntime")
]
),
// testing helper
.target(
name: "AWSLambdaTesting",
dependencies: [
.byName(name: "AWSLambdaRuntime"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOPosix", package: "swift-nio"),
]
),
.testTarget(
name: "AWSLambdaTestingTests",
dependencies: [
.byName(name: "AWSLambdaTesting")
]
),
// for perf testing
.executableTarget(
name: "MockServer",
dependencies: [
.product(name: "Logging", package: "swift-log"),
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOPosix", package: "swift-nio"),
]
),
]
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ``AWSLambdaRuntimeCore``
# ``AWSLambdaRuntime``

An AWS Lambda runtime for the Swift programming language

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Server ecosystem is to shift to newer, more readable, Swift concurrency construc
#### No ownership of the main() function

A Lambda function can currently be implemented through conformance to the various handler protocols defined in
`AWSLambdaRuntimeCore/LambdaHandler`. Each of these protocols have an extension which implements a `static func main()`.
``AWSLambdaRuntime/LambdaHandler``. Each of these protocols have an extension which implements a `static func main()`.
This allows users to annotate their `LambdaHandler` conforming object with `@main`. The `static func main()` calls the
internal `Lambda.run()` function, which starts the Lambda function. Since the `Lambda.run()` method is internal, users
cannot override the default implementation. This has proven challenging for users who want to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
2025-01-02T14:59:29+0100 info LocalLambdaServer : [AWSLambdaRuntimeCore]
2025-01-02T14:59:29+0100 info LocalLambdaServer : [AWSLambdaRuntime]
LocalLambdaServer started and listening on 127.0.0.1:7000, receiving events on /invoke
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ swift run
Building for debugging...
[1/1] Write swift-version--58304C5D6DBC2206.txt
Build of product 'PalindromeLambda' complete! (0.11s)
2025-01-02T15:12:49+0100 info LocalLambdaServer : [AWSLambdaRuntimeCore] LocalLambdaServer started and listening on 127.0.0.1:7000, receiving events on /invoke
2025-01-02T15:12:49+0100 info LocalLambdaServer : [AWSLambdaRuntime] LocalLambdaServer started and listening on 127.0.0.1:7000, receiving events on /invoke
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Loading