AWS Lambda functions and the Linux Static SDK - works!

I just try an simple hello world, to answer your question

print("hello world")

on macOS with

swift build -c release 

ls -al .build/arm64-apple-macosx/release/HelloWorld
-rwxr-xr-x  1 stormacq  staff  55928 Jun 20 15:20 .build/arm64-apple-macosx/release/HelloWorld

When using the Static Linux SDK

export TOOLCHAINS=org.swift.600202406131a                 
PATH_TO_TOOLCHAIN=/Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-13-a.xctoolchain

DYLD_LIBRARY_PATH=$PATH_TO_TOOLCHAIN/usr/lib/swift/macosx $PATH_TO_TOOLCHAIN/usr/bin/swift build -c release --swift-sdk aarch64-swift-linux-musl --target HelloWorld

ls -al .build/aarch64-swift-linux-musl/release/HelloWorld
-rwxr-xr-x  1 stormacq  staff  42116112 Jun 20 15:24 .build/aarch64-swift-linux-musl/release/HelloWorld

It's 40Mb vs 55Kb :-)

Then, I stripped it and it's now 5.9Mb. That's an impressive 86% reduction.
Given that musl libc.a is 2.4Mb and libc++.a is 10Mb, I find that 5.9Mb for an executable that contains both libc and the Swift runtime is not that bad :-)

# on Linux
strip -o stripped HelloWorld

$ ls -alh stripped 
-rwxrwxr-x. 1 ec2-user ec2-user 5.9M Jun 20 13:37 stripped
2 Likes