Minimizing Linux packages for compiled programs

To build Swift programs some Linux packages have to be installed.

But for the distribution of a compiled program most of them should not be needed. I guess only the following two are actually needed:

  • libxml2: not libxml2-dev and only if the XML part of Swift's standard library is used
  • tzdata: for calendar features?

I guess the license of tzdata would allow to include it into the Swift libraries, so in this case and if you do not use the XML part of Swift's standard library, no Linux packages would actually be needed to be installed for running a Swift program, which would be great.


  • Is my judgement correct?
  • If some packages (I would maybe see libxml2 as a spacial case) are still needed to run a Swift program, is there a good chance that this will not be necessary in the near future?
  • What about adding infos on about how to distribute compiled Swift programs on Linux and on Windows, I think this would be helpful.

If FoundationNetworking is linked, many more packages are required, specifically libcurl and its dependencies.

Additionally, you'll need Glibc and libstdc++ in all cases.

For all of these packages you'll need compatible versions installed, usually that means those not older than the versions used to build the executable originally.

My program runs fine without glibc (so is libstdc++ really needed?), and for Ubuntu libstdc++ is preinstalled so my program runs fine on Ubuntu without any additional packages. OK, libcurl is need for networking and libxml2 is needed for the XML part of the Swift standard libraries.

It still would make sense (in my opinion) to narrow down what is needed for the execution of a program, as other packages are listed with a specific version so it would be quite sensible to dispense with them for execution, and maybe for the still needed packages to describe the according use case.

Update: Like libstdc++, libcurl and libxml2 are also preinstalled on Ubuntu according to current and previous manifest files for Ubuntu. So think a distribution for Ubuntu is kind of easy, no installation of Linux packages should be needed. (OK, some people might trim down their installation...)

I don't think this can be true, unless you have custom-built Swift SDK that uses Musl instead of Glibc. Glibc is a dependency of libstdc++, Swift runtime, and Swift stdlib. It can't be linked statically.

Yes, libstdc++ is a dependency of Swift runtime as it's written in C++.

Vapor's templaet Dockerfile only install tzdata and ca-certificates as that's all that's needed with a statically linked app.

Note: Vapor's template currently uses the Swift Slim images because backtrace support is broken and doesn't work with static linking at the moment. So if you want this, you need more dependencies.

You can make the final image very small with chiselled containers if that's your concern as well