Distributing binaries for linuxes (static linking?)

What is the best way to distribute apps written in Swift for random glibc-based linux distributions? I found an issue which indicates that static linking does not work yet, maybe it will work with Swift 5? Alternatively, is there a way to package a binary together with all the foundation libraries and libdispatch?


As far as I know, there is no correct way to distribute Swift binaries yet. They are not portable. @Aciid for sure has better information here.

I see... Is there a division between SDK and runtime libraries? To at least not include dev libraries into docker image...

IIRC there are hardcoded paths etc… in the binary. That's one problem at least.

If static linking worked on Linux (which it may with the Swift 5 snapshots, I haven't tried) distributing binaries on Linux would be fine since everything Swift related would be self contained in the binary. With Swift 4.x there's at least one other issue still being tracked here https://bugs.swift.org/browse/SR-7039

Right, SwiftPM doesn't have a binary distribution story yet. You can package up things together using scripts but there is no builtin way to do that yet.

And, if I've been following the discussions correctly, you need Swift ABI stability before binary distribution is possible. If I understand correctly, Swift ABI stability has been achieved for only Darwin (MacOSX, iOS, tvOS, watchOS) in Swift 5, not Linux, FreeBSD, Windows, etc..

This shouldn't matter for distributing binaries. No ABI stability just means that distributed binaries must be compiled with the same version of swift that is installed on the machine. ABI stability makes binaries future proof (ie: A binary compiled with swift 5 will still work if swift 6 is installed).

And if you're building statically then none of this should matter anyways since all the stdlib and everything will be included in the binary itself.


If static linking worked on Linux (which it may with the Swift 5 snapshots, I haven't tried)

I just tried, latest 5.0 snapshot on Ubuntu 18.04. Does not work still. Seems like Foundation, BlockRuntime and dispatch are not distributed as .a files.

I just wanted to check-in to see if there is any way in the current version of Swift to build static binaries on Linux? When I tried the option, it seemed to just be ignored. Thanks in advance.