Size of the swift runtime and minimal app

There are two parts here:

  • Not embedding parts stemming from unused parts of your source.
  • Discarding unused parts of statically linked libraries (LLVM has the “lto” option for such an optimization).

To my knowledge the first optimization is active (presumably not for all compiler configurations), but the second optimization is not available. It would indeed be nice to know if such an optimization can be activated, or if anything is planned in this direction, and what parts could then be discarded.

Of course the second optimization is more important for non-Apple platforms, as on Apple platforms the libraries are part of the operating system (see this forums topic about static linking on macOS).

(Note that on Linux, you have two choices for static linking: -Xswiftc -static-executable for statically linking “everything”, my understanding is that this includes other Linux packages that are needed so you do not need to install those when you are running the program, or -Xswiftc -static-stdlib for the Swift standard libraries only. There is no static linking on Windows yet.)

1 Like