-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for resources when packaging using the SwiftPM plugin (#333)
* Add support for resources when packaging using the SwiftPM plugin. * Copy the resources directory to the working directory instead of recreating the directroy structure. * Add resource packaging example. * Use the bundle's url function to locate the file url. * Fix year for soundness check. --------- Co-authored-by: Sébastien Stormacq <sebastien.stormacq@gmail.com>
- Loading branch information
1 parent
872183b
commit 35e0919
Showing
4 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftAWSLambdaRuntime open source project | ||
// | ||
// Copyright (c) 2021 Apple Inc. and the SwiftAWSLambdaRuntime project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import AWSLambdaRuntime | ||
import Foundation | ||
|
||
// in this example we are reading from a bundled resource and responding with the contents | ||
|
||
@main | ||
struct MyLambda: SimpleLambdaHandler { | ||
func handle(_ input: String, context: LambdaContext) async throws -> String { | ||
guard let fileURL = Bundle.module.url(forResource: "hello", withExtension: "txt") else { | ||
fatalError("no file url") | ||
} | ||
return try String(contentsOf: fileURL) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// swift-tools-version:5.7 | ||
|
||
import class Foundation.ProcessInfo // needed for CI to test the local version of the library | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "swift-aws-lambda-runtime-example", | ||
platforms: [ | ||
.macOS(.v12), | ||
], | ||
products: [ | ||
.executable(name: "MyLambda", targets: ["MyLambda"]), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha"), | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "MyLambda", | ||
dependencies: [ | ||
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), | ||
], | ||
path: ".", | ||
resources: [ | ||
.process("hello.txt"), | ||
] | ||
), | ||
] | ||
) | ||
|
||
// for CI to test the local version of the library | ||
if ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"] != nil { | ||
package.dependencies = [ | ||
.package(name: "swift-aws-lambda-runtime", path: "../.."), | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello, World! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters