Hey, I've been experimenting with -static-stdlib
a bit on Android. The flag has been around for some time- it was added for linux with Swift 3.1- but 5.2 simply added the libdispatch and Foundation static libraries too. However, the linker flags aren't properly set for -static-stdlib
, probably because it's not really tested.
With a small Swift test executable that links against swiftDispatch, I found that I had to also add the -lDispatchStubs
flag to get it to link and run, ie swiftc -static-stdlib dispatchExample.swift -lDispatchStubs
.
For a small Foundation executable, I had to modify usr/lib/swift_static/linux/static-stdlib-args.lnk
to add -lCoreFoundation
before the Swift ICU libs, ie before -licui18nswift
and so on, because the CoreFoundation static library depends on ICU and must come before them (adding it on the command-line won't work, as it comes after them then). Then, the following command worked, swiftc -static-stdlib foundationExample.swift -lDispatchStubs -luuid
.
I don't know if these are static libraries that swift-autolink-extract
should be detecting, as I haven't looked into how that works, or if they should be added to the bash script that generates the static-stdlib linker file. You can always add them yourself for now.