You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looks like -static makes the linker not pick up .so links to dynamic libraries. But some (like libuuid) only exist as dynamic libraries. Or in other words, even when linking statically, this still needs to build a dynamically linked binary.
I did a quick test last week, it worked, it did noticeably improve cold start, QED.
Revisited it today with partial success.
Looks like -static makes the linker not pick up .so links to dynamic libraries. But some (like libuuid) only exist as dynamic libraries. Or in other words, even when linking statically, this still needs to build a dynamically linked binary.
static-stdlib settings, as defined in /usr/lib/swift_static/linux/static-stdlib-args.lnk link statically some libraries and dynamically others.
Examples:
all static
# swift build --product HelloWorldAPIPerf -c release -Xswiftc -static-executable -Xswiftc -lDispatchStubs
# ldd .build/release/HelloWorldAPIPerf
not a dynamic executable
Yes, I was specifically trying with Foundation (with static linking there should be very little reason to avoid it in the first place). This introduces the problematic libuuid dependency.
I should eventually disable SIP and check what the linker is actually doing. Not sure when I'll find the time.
swift lambda already specifies both, -Xswiftc -static-stdlib -Xswiftc -static-executable, not sure which one wins :-) But a build doesn't go through for other reasons:
<module-includes>:5:10: note: in file included from <module-includes>:5:
#include "private_includes/utmp.h"
^
/usr/local/lib/swift/dst/x86_64-unknown-linux/swift-5.3-amazonlinux2.xtoolchain/x86_64-amazonlinux2.sdk/usr/lib/swift/linux/x86_64/private_includes/utmp.h:1:10: note: in file included from /usr/local/lib/swift/dst/x86_64-unknown-linux/swift-5.3-amazonlinux2.xtoolchain/x86_64-amazonlinux2.sdk/usr/lib/swift/linux/x86_64/private_includes/utmp.h:1:
#include <utmp.h>
^
utmp.h doesn't actually seem to be missing, it is stddef.h.
It gets a little further when specifying -Xswiftc -I -Xswiftc /usr/local/lib/swift/dst/x86_64-unknown-linux/swift-5.3-amazonlinux2.xtoolchain/x86_64-amazonlinux2.sdk/usr/include/linux, but ends up in redefinition errors.
That's something @fabianfett might be able to answer. I think it is possible, but maybe not with the current SPMDestinations toolchain version, that needs an update eventually.
Activity
pokryfka commentedon Aug 14, 2020
It's on my todo list as well.
@fabianfett post compilation flags he used: awslabs/swift-aws-lambda-runtime#17 (comment)
pokryfka commentedon Aug 14, 2020
I can confirm that adding
fixed static compilation in my setup on swift:5.2-amazonlinux2 docker image with
glibc-static./usr/lib/swift_static/linux/static-executable-args.lnkbuild with:
helje5 commentedon Aug 14, 2020
Didn't know about that static-executable-args.lnk file. Might be enough to just put that into the xtoolchain?
Add -static-executable and -latomic
helje5 commentedon Aug 16, 2020
Looks like
-staticmakes the linker not pick up.solinks to dynamic libraries. But some (like libuuid) only exist as dynamic libraries. Or in other words, even when linking statically, this still needs to build a dynamically linked binary.pokryfka commentedon Aug 20, 2020
I did a quick test last week, it worked, it did noticeably improve cold start, QED.
Revisited it today with partial success.
static-stdlibsettings, as defined in/usr/lib/swift_static/linux/static-stdlib-args.lnklink statically some libraries and dynamically others.Examples:
all static
static + dyn
static + dyn including libuuid
all dyn
Now I guess I should have mentioned that and it does make big difference,
HelloWorldAPIPerfdoes not useFoundation.So while the approach above should be useful, I have not yet done it with
Foundation.helje5 commentedon Aug 20, 2020
Yes, I was specifically trying with Foundation (with static linking there should be very little reason to avoid it in the first place). This introduces the problematic libuuid dependency.
I should eventually disable SIP and check what the linker is actually doing. Not sure when I'll find the time.
helje5 commentedon Aug 20, 2020
Hm, why is
--export-dynamicrequired, that feels wrong 🤔helje5 commentedon Feb 3, 2021
FWIW, AFAIK Swift 5.3 brought static linking fixes, which might solve the whole Radar. Need to figure out the required flags.
https://forums.swift.org/t/static-linking-on-linux-in-swift-5-3-1/41989
-static-stdlib: only statically link Swift stdlib, Foundation, Dispatch, but not ICU-static-executable: self contained executableSo we probably need the first when building for a regular Ubuntu and the latter for Amazon Linux 🤔
Add CoreFoundation uuid to the static libs
helje5 commentedon Feb 3, 2021
swift lambdaalready specifies both,-Xswiftc -static-stdlib -Xswiftc -static-executable, not sure which one wins :-) But a build doesn't go through for other reasons:Which we have in
Note sure why this works for dynamic, but not for static. The include is from the
glibc.modulemapwhich is present in both, SDK and toolchain.helje5 commentedon Feb 3, 2021
utmp.hdoesn't actually seem to be missing, it isstddef.h.It gets a little further when specifying
-Xswiftc -I -Xswiftc /usr/local/lib/swift/dst/x86_64-unknown-linux/swift-5.3-amazonlinux2.xtoolchain/x86_64-amazonlinux2.sdk/usr/include/linux, but ends up in redefinition errors.benrosen78 commentedon Jan 12, 2023
Hi there, has there been any new success with getting Foundation to compile statically for AWS lambdas?
helje5 commentedon Jan 12, 2023
That's something @fabianfett might be able to answer. I think it is possible, but maybe not with the current SPMDestinations toolchain version, that needs an update eventually.