Cross compiling from macOS to Linux

Hey folks,

After seeing lots of conversations here about cross compilation from macOS to Linux, and spending some time building Linux binaries myself in docker containers, I decided to try and make it easier to create toolchains for this use case. I just released this tool GitHub - keith/swiftpm-linux-cross: Cross compile from macOS to Linux with Swift Package Manager which can currently generate Ubuntu bionic / focal, x86_64 / arm64 toolchains for building dynamic or static-stdlib binaries. I've successfully tested this against a fresh Vapor project and swiftlint, but I'm sure there are some unknown edge cases around.

For folks who have wanted this workflow for their Swift on Linux projects, I'd love you to try it out and file any issues you hit. I hope some of you find this useful!

6 Likes

You might also want to take a look at: GitHub - CSCIX65G/SwiftCrossCompilers: SPM toolchain to cross compile Raspberry Pi (arm64) and Amd64 Swift binaries on macOS which does something similar. I used to distribute MacOS Installer packages there, but the compiler toolchain got so big I had to stop that bc GitHub would't let me put up a 4Gb artifact. The most interesting thing for me is being able to generate distro-less docker containers.

1 Like