<!--- Provide a general summary of your changes in the Title above -->
## Issue \#
<!--- If it fixes an issue, please link to the issue here -->
https://github.com/awslabs/swift-aws-lambda-runtime/issues/644
## Description of changes
<!--- Why is this change required? What problem does it solve? -->
- Added `--container-cli` option to the archive SwiftPM plugin so users
can choose Docker (default) or Apple container
- Implemented Apple container support by switching pull/run commands to
`container image pull` and `container run`
- Documented the Apple container path in readme.md
- swift test passed
## New/existing dependencies impact assessment, if applicable
<!--- No new dependencies were added to this change. -->
<!--- If any dependency was added / modified / removed,
THIRD-PARTY-LICENSES must be updated accordingly. -->
N/A
## Conventional Commits
<!--- Please use conventional commits to let us know what kind of change
this is.-->
<!--- More info can be found here:
https://www.conventionalcommits.org/en/v1.0.0/-->
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
---------
Co-authored-by: Sebastien Stormacq <stormacq@amazon.lu>
## Issue #
Related to intermittent CI crashes with Signal 11 (SIGSEGV) during
`swift package archive` on Linux x86_64 (Ubuntu 24.04)
## Description of the changes
Replaces `FileHandle.readabilityHandler` with a manual blocking read
loop using `availableData` on a serial `DispatchQueue` in the
`Utils.execute` method of the AWSLambdaPackager plugin.
On Linux, `FileHandle.readabilityHandler`'s setter internally calls
`_bridgeAnythingToObjectiveC`, which triggers `swift_dynamicCast` /
`swift_conformsToProtocol`. When the Swift runtime is concurrently
resolving type metadata on other threads, this causes a bad pointer
dereference crash in `_dispatch_event_loop_drain`. The new approach uses
a `while` loop calling `availableData` (blocks until data arrives,
returns empty `Data` at EOF), completely avoiding the problematic
Foundation/ObjC bridging code paths.
## New/existing dependencies impact assessment, if applicable
No new dependencies were added to this change.
## Conventional Commits
`fix: replace FileHandle.readabilityHandler with manual read loop in
AWSLambdaPackager plugin`
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
---------
Co-authored-by: Sebastien Stormacq <stormacq@amazon.lu>
Fix a rare crash in CI on the archive plugin.
The crash is a race condition in `PluginUtils.swift`'s execute method.
The code set a `terminationHandler` on the `Process` that called
`readToEnd()` on the pipe, while simultaneously the `readabilityHandler`
could still be firing on the same pipe's file handle. On Linux (x86_64,
Ubuntu 24.04 in CI), this race corrupts memory during Swift runtime
metadata resolution (`swift_conformsToProtocol,
_swift_getGenericMetadata`), which manifests as the `SIGSEGV` we're
seeing in `_dispatch_event_loop_drain`.
The fix:
I removed the `terminationHandler` entirely. Since `waitUntilExit()` is
already called synchronously, we know the process is done.
After `waitUntilExit()`, we set `readabilityHandler = nil` to stop the
async reads, then do one final `readToEnd()` on the output queue to
drain any remaining data.
This eliminates the race between the readability handler and the
termination handler competing over the same file handle.
Co-authored-by: Sebastien Stormacq <stormacq@amazon.lu>
- Adjust notice, security reporting, code of conduct, contribution
process to the standard AWS documents
- Adjust GitHub issue templates to AWS standard ones.
- Adjust the license header in all source files
---------
Co-authored-by: Sebastien Stormacq <stormacq@amazon.lu>
A proposal for a new set of SwiftPM plugins to facilitate the
scaffolding, build, archive, and deployment of Lambda functions.
This is a call for comments to finalize the design before starting an
actual implementation
Resources are not included in the archive on Linux
https://github.com/swift-server/swift-aws-lambda-runtime/issues/505
In addition, the script that checks if the resources are correctly
included in an archive when building on Linux is not working.
It failed to detected missing resources.
This patch fix both the plugin and the CI script
Instructions for customizing the output path are incorrect
### Motivation:
`displayHelpMessage` was incorrect - it claimed that the output path was
customizable via a `--output-directory` flag, but the code actually
looks for `--output-path`
### Modifications:
Changing the help message here, instead of the code, in case existing
projects already depend on `--output-path`
### Result:
`displayHelpMessage` will show the correct instructions
When including resources in the package and packaging on Ubuntu,
`FileManager` throws a FilePermission error. The docker daemon runs as
root and files to be copied are owned by `root` while the archiver runs
as the current user (`ubuntu` on EC2 Ubuntu). The `FileManager` manages
to copy the files but throws an error after the copy. We suspect the
`FileManager` to perform some kind of operation after the copy and it
fails because of the `root` permission of the files.
See
https://github.com/swift-server/swift-aws-lambda-runtime/issues/449#issuecomment-2595978246
for a description of the problem.
This PR contains code to reproduce the problem, a very simple
workaround, and an integration test.
The workaround consists of
- trapping all errors
- verify if the error is the permission error (Code = 513)
- verify if the files have been copied or not
- if the two above conditions are met, ignore the error, otherwise
re-throw it
I would rather prefer a solution that solves the root cause rather than
just ignoring the error.
We're still investigating the root cause (see [this
thread](https://forums.swift.org/t/filemanager-copyitem-on-linux-fails-after-copying-the-files/77282)
on the Swift Forum and this issue on Swift Foundation
https://github.com/swiftlang/swift-foundation/issues/1125
* do not force unwrap
Revert a change from #d2bd7f1aae1fc9455b208567ba5d85e42463c82c that caused the plugin to crash
* test stdout for nil
---------
Co-authored-by: Fabian Fett <fabianfett@apple.com>
* Add Support For Copying All Resources Into Final Executable
* Run formatter
---------
Co-authored-by: Sébastien Stormacq <sebastien.stormacq@gmail.com>
* Require Swift 6
* Apply formatter
* Disable 5.8, 5.9, and 5.10 checks
* Remove -warnings-as-errors for now
* Ensure plugin compiles in Swift 6 language mode
* 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>
motivation: sometimes, you need to use a customized local docker image and `docker pull` don’t have to be called
changes:
* add `--disable-docker-image-update` plugin flag to disable `docker pull` call
motivation: add an easy wasy for lambda users to package their lambda and upload it to AWS
changes:
* add SwiftPM plugin to package the lambda as zipfile, with the verb "archive"
* use docker to build and package the lambda(s) on macOS and non-amazonlinux
* build directly on when on amazonlinux, zip correctly
Co-authored-by: Yim Lee <yim_lee@apple.com>
Co-authored-by: Fabian Fett <fabianfett@apple.com>