Can the Swift compiler create a single executable for my application?

Viewed 792

I'm currently trying to create an executable for my Vapor application, but I just can't run it on my server.

My expectation was that it would be able to create a single application with all my code and the dependencies. My current references are .NET and Go, where you can create a single executable from the code and deploy this standalone file - which makes it amazingly simple to deploy.

I tried compiling and executing it on Docker, but no such luck - it failed with some libSwift something missing.

So, can Swift do something like this?

Looking forward to your answers

1 Answers

You can build a binary that statically links the standard library or build a completely self contained binary using the static linking flags introduced in Swift 5.3.1 - -static-stdlib and -static-executable. See this forum post for more details.

Note that swift still has some dependencies on ICU and libc so aren't completely portable yet

Related