Building iOS apps from Linux
· 2 min read
I use an iPhone and a Linux laptop, and I wanted to build an app for my own phone. The first thing you learn is that Apple's tools for that, Xcode and its build tools, only run on macOS.
but this was for one very particular use case so it wasn't worth buying a Mac or paying for one by the hour, so I was looking for something quick that cost nothing.
Is it really that hard?
Mostly, yes, with some nuance. Before settling on anything I looked at the options:
- Rent a Mac in the cloud. Services like MacStadium or MacinCloud give you a remote Mac with Xcode. It works, but you're developing through a remote desktop and paying by the hour.
- Let a cloud service build it. If you write your app in React Native with Expo, or in Flutter, services like Expo's EAS Build or Codemagic compile the iPhone version on their own Macs, so you never touch one yourself. That's a real option, as long as you're happy with those frameworks.
I wanted to write a native SwiftUI app and install it straight from my laptop onto my phone, for free. For that there's really one option.
xtool
xtool is an open-source replacement for Xcode's build tools. It builds Swift apps on Linux, signs them with your Apple ID, and installs them on an iPhone over USB. and it's the reason Jot exists.
It isn't a full Xcode. There's no visual interface builder, and as far as I know it can't upload apps to the App Store yet, so it's for building and running apps on your own devices. and well, that's exactly what I needed.
Setting it up on Arch
Swift itself comes from the AUR, and usbmuxd, for talking to the phone over USB, from Arch's own repos. The one part you can't avoid Apple for is the iOS SDK, which only ships inside Xcode, so you download the Xcode installer once in a browser and let xtool pull the SDK out of it:
xtool setup # sign in, point it at the downloaded Xcode .xip
xtool new MyApp && cd MyApp
xtool dev # build and install on the iPhone plugged in over USBthe catch
With a free Apple ID, apps installed this way stop opening after seven days and need reinstalling. For a journal I use every day, losing a week of entries because I forgot to refresh it would defeat the whole purpose.
So for Jot I wrote a small helper that backs up the app's data over USB and reinstalls it before it expires. tbh I never notice it run.
So, is it hard?
Without xtool, building and installing a native iPhone app from Linux would mean a Mac somewhere, yours or rented. With it, it's an afternoon of setup and one Apple download, and then it just works.
If you're on Linux with an iPhone too, I also wrote about texting from my laptop.