awslabs / aws-sdk-swift

Apache License 2.0
398 stars 79 forks source link

Compile error when adding dependency for AWSIoT on Linux #495

Closed dave-moser closed 2 years ago

dave-moser commented 2 years ago

Description

Attempting to compile an SPM project using version 0.0.15 of the AWSSwiftSDK and adding the AWSIoT module. During the compile, an error is thrown stopping the compile. I am performing the compile on Linux in the swift:5.4.3-amazonlinux2 docker image. I built a similar project in Xcode and did NOT get an error. I was able to build.

Context

I am ultimately attempting to write a Lambda function in Swift that interacts with AWS IoT Core.

Environment

Reproduction Steps

Dockerfile FROM swift:5.4.3-amazonlinux2 as builder

RUN yum -y install git jq tar zip openssl-devel WORKDIR /build-lambda RUN mkdir -p /Sources/swift-lambda-function/ RUN mkdir -p /Tests/swift-lambda-function/ ADD /Sources/ ./Sources/ ADD /Tests/ ./Tests/ COPY Package.swift . RUN cd /build-lambda && swift package clean && swift build -c release

Observed Behavior

The compile throws an error. I do not see a specific error message. There are many warnings, though, regarding 'additionalMetricsToRetain' is deprecated: Use additionalMetricsToRetainV2.

It does not look like that is the error, but I do not see any specific error.

I have seen this in the past with prior reported compilation issues on Linux that were a segfault with not much info displayed.

If I change the dependency to something else like AWSDynamoDB, it compiles without error.

Expected Behavior

app should compile

Possible Solution

dave-moser commented 2 years ago

attached is the output from the swift build in the Docker container if it is helpful. I do not see any specific error aws-sdk-iot-errors.txt .

wooj2 commented 2 years ago

Thanks for the detailed bug report. I did not try building on docker, but I tried compiling on an AL2 instance with swift tools 5.4.3 and I was able to get my project to compile.

Despite having the same version of Swift, I did have a couple differences in my dev environment:

With regards to "why this doesn't work in a container" -- I suspect there is some difference in compiling within a container which makes the swift compiler "unhappy". For example, Dynamo's DynmaoDBClient.swift is 217kb, where IoT's client.swift is 770kb. Similarly, Dynamo's "Models.swift" file is 1.34MB while IoT's is at 3.52MB -- One theory is that swift isn't giving you an error because these files are just too large and swift is just segfaulting.

Let me know if running a container is critical to your application -- if so, i can try some to break up these files and see where things are failing.

dave-moser commented 2 years ago

Thanks fo looking into it. Using Docker for the builds is crucial. Most of the work we do is with Server Side Swift and developing on a Mac. For example, deploying Lambda functions to AWS. Using Docker is really the only practical way to compile the Swift code on your Mac for a deployment to AWS.

dave-moser commented 2 years ago

Thanks for the info John. I bumped the RAM allocated to Docker on my machine from the default of 2GB up to 4GB and the compile worked. Good to know. Thanks!