Search code examples
swiftubuntuvaporserver-side-swift

Does Swift executable binary need the .swiftmodule, .swiftdoc and .build files to run?


I'm writing my Swift app for Ubuntu using Vapor. And my mission is to have the smallest Docker image for production. I've trimmed down my image significantly but I wanted to know, just out of curiosity, does my final executable need all the compiled .module, .doc and .build files in the same directory?


Solution

  • tl;dr: No.

    The folders/files you listed are byproducts of the build process and can be safely discarded.

    When it comes to distribution, your application is just like any other Linux executable. You must have all dynamically linked libraries available on the target system.

    These include the runtime libraries of the Swift toolchain plus any compiled C modules your application (or the framework beneath it) links with (*).

    You can check the dependencies of the executable using the ldd command. Some of them are available as packages, some of them will need to be copied to the target system manually.


    (*) In case of a Vapor 2 application, such C modules are libCHTTP.so and libCSQLite.so, which are placed in your build folder.