-
Notifications
You must be signed in to change notification settings - Fork 104
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
Add support for resources when packaging using the SwiftPM plugin #333
Merged
sebsto
merged 6 commits into
swift-server:main
from
camdenfullmer:plugin-resources-support
Aug 5, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
86dd1a7
Add support for resources when packaging using the SwiftPM plugin.
camdenfullmer 91e0fec
Merge branch 'main' into plugin-resources-support
sebsto 7554ed7
Copy the resources directory to the working directory instead of recr…
camdenfullmer 05dee34
Add resource packaging example.
camdenfullmer 33f2952
Use the bundle's url function to locate the file url.
camdenfullmer 7623f28
Fix year for soundness check.
camdenfullmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't sure if there was a better way to get the package name when creating the resources directory name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the only way to retrieve a package name.
See https://github.com/swiftlang/swift-package-manager/blob/b24cc8b547f952ee4a954db939f115a26946fe2b/Sources/PackagePlugin/PackageModel.swift#L16
The other option is to use the directory name but it's not necessarily the same.