swift-server / swift-aws-lambda-runtime

Swift implementation of AWS Lambda Runtime
Apache License 2.0
1.12k stars 100 forks source link

Compile error on Windows #327

Closed finestructure closed 2 weeks ago

finestructure commented 1 month ago

Expected behavior

I'm trying to build a project on Windows that has (but doesn't use) this package as a transitive dependency. It leads to a failure early on during package resolution:

warning: 'spi-builder': dependency 'swift-crypto' is not used by any target
error: fatalError
C:\Users\sven_\Projects\spi-builder\.build\checkouts\swift-aws-lambda-runtime\Plugins\AWSLambdaPackager\Plugin.swift:195:25: error: type 'any Error' has no member 'unsupportedPlatform'
            throw Error.unsupportedPlatform("can't or don't know how to create a zip file on this platform")
                  ~~~~~ ^~~~~~~~~~~~~~~~~~~
C:\Users\sven_\Projects\spi-builder\.build\checkouts\swift-aws-lambda-runtime\Plugins\AWSLambdaPackager\Plugin.swift:201:28: error: cannot find 'arguments' in scope
                arguments: arguments,
                           ^~~~~~~~~
[1/1] Compiling plugin AWSLambdaPackager

The problem appears to be

            #if os(macOS) || os(Linux)
            let arguments = ["--junk-paths", "--symlinks", zipfilePath.string, relocatedArtifactPath.string, symbolicLinkPath.string]
            #else
            throw Error.unsupportedPlatform("can't or don't know how to create a zip file on this platform")
            #endif

in Plugin.swift.

The dependency is coming into my project via another project of ours that creates a lambda to upload data to S3. This project runs on Linux and is imported in order to share data structures & logic. I can probably work around this by creating yet another project that moves those types but it'd be rather awkward.

I wonder if the plugin could be simply disabled such that it won't bail out my build even when it's not being used?

Actual behavior

Don't abort the build unless the plugin is being actively used.

Steps to reproduce

Create a project that transitively imports swift-aws-lambda-runtime and doesn't use the plugin. The build will fail on Windows.

If possible, minimal yet complete reproducer code (or URL to code)

No response

What version of this project (swift-aws-lambda-runtime) are you using?

1.0.0-alpha.2

Swift version

5.10

Amazon Linux 2 docker image version

No response

finestructure commented 1 month ago

I completely misread the error - it's a compile error, not a runtime error 🤦‍♂️

error: type 'any Error' has no member 'unsupportedPlatform