Test your Swift Packages Linux Compatibility on Mac
Ever wondered how to test your Swift code’s compatibility with Linux from your Mac without diving into Docker? In this article, I’ll share a simple command that makes the process effortless!
Recently, I encountered a situation where I needed to extract Swift networking code from one of my applications for reuse on a Vapor server. While the code built perfectly on my Mac, I ran into multiple errors when deploying it to my server. This prompted me to look for a way to easily test the code’s compatibility with Linux, which is the OS typically running on servers. Luckily, I found this article by Ole Begemann from 2020 that saved me from having to learn Docker.
In his article, Ole provides a straightforward approach to running Swift code in a Linux environment with a single command. All you need to do is to install the free Docker Desktop App on your Mac. But the command seemed quite lengthy and hard to remember, so I wanted to simplify things even further. I ended up with an approach where all I need to remember was swift-linux
. Here's how:
Simplifying the Docker Command
First, I decided to further simplify Ole’s command for brevity:
docker run --rm -it -v "$(pwd):/src" -w "/src" swift