awslabs / aws-sdk-swift

Apache License 2.0
403 stars 80 forks source link

support building with swift static linux sdk #1785

Open marcelo-paredes opened 1 month ago

marcelo-paredes commented 1 month ago

Describe the feature

building a project using the SDK with swift build --swift-sdk aarch64-swift-linux-musl will fail because aws-crt-swift/aws-common-runtime/aws-c-common/source/posix/system_info.c tries to include execinfo.h

After removing this manually, it fails again in .build/checkouts/smithy-swift/Sources/ClientRuntime/Networking/Http/CRT/CRTClientEngine.swift since it only checks for Glibc on Linux, which is not available using the static Linux SDK. When canImport(Musl), that should be imported instead.

#if canImport(Glibc)
    import Glibc
#elseif canImport(Musl)
    import Musl
#endif

Use Case

This is necessary to be able to build a binary using the aws swift sdk in a machine (running either Linux or macOS) and then install the binaries to be used in some other linux machine without the need of copying (possibly incompatible) dynamic libraries/shared objects along with it.

Proposed Solution

both steps may have other consequences in code that requires Darwin or Glibc

Other Information

No response

Acknowledgements

jbelkins commented 1 month ago

Hi @marcelo-paredes! Thanks for bringing this up. Until now, we hadn't really looked at statically-linked Linux binaries.

aws-crt-swift is maintained by a different team, their repo is at https://github.com/awslabs/aws-crt-swift . I suggest you file an issue there for the best response.

In the meantime, I'll start looking at this project and https://github.com/smithy-lang/smithy-swift to see what we can do to get statically linked binaries to work.