Making three of my Mac apps build for Apple Silicon
This year’s WWDC keynote brought with it some major changes to macOS, both in terms of its look, but most importantly, to what the future of Mac hardware looks like. With Apple Silicon, Mac developers have to create Universal Binaries of their apps.
I had the opportunity to do just that for my Mac apps today, and I’d like to share the results and some overall stats with you. Of course this is just my experience, so your mileage may vary, as they say.
One of the most important things to keep in mind is that the more external dependencies that you have, the more complicated it’s going to be to get a universal build up and running, especially if those dependencies are currently being included in your app as pre-compiled binaries.
Another disclaimer is that I don’t yet have access to a Mac powered by Apple Silicon to actually run the builds that I’ve created on — so there could still be some work that I have to do — but given that I don’t have any code that’s low-level enough to be concerned with the underlying CPU architecture that it’s running on, I believe these builds are good to go.
The numbers
Let’s start with some numbers. I have tried and successfully built three of my apps for Apple Silicon: ChibiStudio, FusionCast, and AirBuddy. AirBuddy¹ is an AppKit app, it’s distributed directly to customers as a notarized build, and it has approximately 27k lines of code — mixing Swift, Objective-C, C++ and Objective-C++. FusionCast is also an AppKit app, distributed both directly and via the App Store, and it has approximately 3k lines of Swift code. Finally, ChibiStudio² is a Catalyst app, and has approximately 50k lines of Swift code.
It took me a total of around 30 minutes to successfully archive all of those apps as Universal 2 binaries, containing both x86_64
and arm64
slices. No code changes were required, but I did stumble upon two details that I would like to share with you now.
Getting the right build of Xcode
At the time of writing, Apple is distributing two separate builds of Xcode in the developer portal. The version called “Xcode 12 for macOS Universal Apps beta” is the one with support for building Universal 2 binaries, so make sure that’s the one you have if you wish to build your Mac apps for Apple Silicon.
I expected to have to change a few build settings manually in order to enable Universal 2 for a given target, but as far as I can see, that was all done automatically by Xcode. If you have changed your “supported architectures” build setting though, you may need to revert that setting to its default value.
To change a build setting back to its default value in Xcode, select the setting within the list and press delete.
Pitfalls that I have encountered
There were only two things that I had to change in order for my apps to compile successfully. The first was related to having resource bundles with bitcode turned on. That setting must be off for resource bundles. I probably enabled it accidentally at some point, but turning it off was all that was needed in order to get ChibiStudio to build successfully as a Universal 2 binary.
The other one is related to dependencies. While I prefer to avoid external dependencies as much as possible, sometimes they are needed to perform some specialized type of work. In FusionCast, I use a popular solution to generate App Store receipt validation code, but it requires OpenSSL. Since the version of OpenSSL that I have on my Mac is not ready for arm64
, I temporarily disabled that functionality until I can sort that out.
Try to setup build flags that enable you to turn off certain external dependencies if necessary. That way, you can still test your app’s main functionality using the new versions of Xcode, without having to wait for a given dependency to be updated.
Conclusion
Apple were not exaggerating when they said that it would only take “a few days” for most apps to be ready for Apple Silicon. In fact, I think they were actually under-promising. I’m really happy that I was able to get my apps building so quickly. The next step will be to actually run them on a DTK machine to see if anything actually breaks.
² ChibiStudio for Mac is not publicly available yet.
Fast and rock-solid Continuous Integration. Automatically build, test and distribute your app on every Pull Request — which is perfect for teams that are now working remotely, as you’ll quickly get feedback on each change that you make. Try out their new, improved free tier to get started.