Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift cross compile to single linux binary

Tags:

Is it possible to compile a swift binary from an OS X computer so that it runs on a server running Linux as a single binary without no extra libraries that need to be dynamically linked?

I'm thinking something like passing a -target to the swift command and passing another parameter to let it statically link all dependencies, but I'm not sure what the exact commands are.

The exact value for -target seems to be rather elusive.

Do I need to know the exact target distribution to be able to pass the correct string to the -target parameter?

like image 769
hasen Avatar asked Jun 01 '17 07:06

hasen


Video Answer


1 Answers

From reading the sources on github

  • target would be Linux
  • machine would be x86_64

This gets called by the primary build script

This how ever answers a part of the question

The exact value for -target seems to be rather elusive.

Install a GCC toolchain for Mac OSX that can retarget Linux, one repo that I can see is OSXCross, for example.

Supply the values to the environment variables to GCC prior to running the script, that references that toolchain.

Unfortunately, that does not guarantee it will work, but give it a try and see what happens.

like image 185
t0mm13b Avatar answered Oct 10 '22 15:10

t0mm13b