Skip to content
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 Examples/HelloWorldNoTraits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This example disables all the traits. To disable one or several traits, modify `

```swift
dependencies: [
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0-beta", traits: [])
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "3.0.0", traits: [])
],
```

Expand Down
56 changes: 56 additions & 0 deletions Sources/AWSLambdaPluginHelper/lambda-init/Initializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import FoundationEssentials
import Foundation
#endif

/// The `SupportedPlatform.MacOSVersion` matching the `LambdaSwift 2.0` availability macro.
private let minimumMacOSVersion = "v15"

@available(LambdaSwift 2.0, *)
struct Initializer {

Expand Down Expand Up @@ -59,6 +62,14 @@ struct Initializer {
with: ""
)
print("✅ Lambda function written to \(relativePath)")

// The runtime API is only available on macOS 15 or later. Without the matching
// platform requirement, the generated function does not compile on macOS.
try self.addMacOSPlatformRequirement(
to: configuration.destinationDir,
verboseLogging: configuration.verboseLogging
)

print("📦 You can now package with: 'swift package lambda-build'")
} catch {
print("🛑 Failed to create the Lambda function file: \(error)")
Expand All @@ -68,6 +79,51 @@ struct Initializer {
}
}

/// Adds the macOS platform requirement of `AWSLambdaRuntime` to the package manifest.
///
/// The runtime API is annotated with `@available(LambdaSwift 2.0, *)`, an availability macro
/// that expands to `macOS 15.0`. A package that does not declare that platform requirement
/// fails to build on macOS with "is only available in macOS 15.0 or newer".
///
/// `platforms` is set by appending an assignment at the end of the manifest rather than by
/// inserting an argument into the `Package(...)` call. `Package` is a class, so mutating it
/// after initialization is valid, and appending needs no parsing of the existing manifest.
private func addMacOSPlatformRequirement(to destinationDir: URL, verboseLogging: Bool) throws {
let manifestURL = destinationDir.appendingPathComponent("Package.swift")

guard FileManager.default.fileExists(atPath: manifestURL.path) else {
print("⚠️ No Package.swift found at \(manifestURL.path).")
print(" Add 'platforms: [.macOS(.\(minimumMacOSVersion))]' to your package manifest manually.")
return
}

let manifest = try String(contentsOf: manifestURL, encoding: .utf8)

// Don't override platform requirements the developer already declared.
let declaresPlatforms = manifest.split(separator: "\n").contains { line in
let statement = line.trimming(while: \.isWhitespace)
return statement.hasPrefix("platforms:") || statement.hasPrefix("package.platforms")
}
guard !declaresPlatforms else {
if verboseLogging {
print("Package.swift already declares platform requirements, leaving it unchanged")
}
return
}

let existing = manifest.hasSuffix("\n") ? manifest : manifest + "\n"
try """
\(existing)
// The AWSLambdaRuntime API requires macOS 15 or later.
package.platforms = [
.macOS(.\(minimumMacOSVersion))
]

""".write(to: manifestURL, atomically: true, encoding: .utf8)

print("✅ Added 'package.platforms = [.macOS(.\(minimumMacOSVersion))]' to Package.swift")
}

/// Finds the main entry point Swift file in the Sources directory.
///
/// Strategy:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ let package = Package(
.macOS(.v15)
],
dependencies: [
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0")
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "3.0.0")
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ let package = Package(
.executable(name: "PalindromeLambda", targets: ["PalindromeLambda"])
],
dependencies: [
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0")
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "3.0.0")
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
.executable(name: "PalindromeLambda", targets: ["PalindromeLambda"])
],
dependencies: [
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0")
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "3.0.0")
],
targets: [
.executableTarget(
Expand Down
2 changes: 1 addition & 1 deletion Sources/AWSLambdaRuntime/Docs.docc/lambda-handlers.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ let package = Package(
name: "MyLambda",
platforms: [.macOS(.v15)],
dependencies: [
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"),
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "3.0.0"),
.package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"),
],
targets: [
Expand Down
2 changes: 1 addition & 1 deletion Sources/AWSLambdaRuntime/Docs.docc/managed-instances.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The managed instances support is implemented behind a Swift package trait (`Mana
dependencies: [
.package(
url: "https://github.com/awslabs/swift-aws-lambda-runtime.git",
from: "2.0.0",
from: "3.0.0",
traits: [
// Keep other default traits but exclude ManagedRuntimeSupport
"FoundationJSONSupport",
Expand Down
2 changes: 1 addition & 1 deletion Sources/AWSLambdaRuntime/Docs.docc/quick-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ let package = Package(
.executable(name: "MyFirstLambdaFunction", targets: ["MyFirstLambdaFunction"]),
],
dependencies: [
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"),
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "3.0.0"),
],
targets: [
.executableTarget(
Expand Down
Loading