Remote Caching Apple .xcframeworks

Andrew Aquino
Shred Engineering
Published in
3 min readApr 10, 2021

--

So Apple loves to come in and just switch things up and then have the developers play catch up once in a while.

iOS 14 & .xcframework

In this particular scenario, iOS 14 introduces a new framework typed.xcframework. It essentially removes the need to create multiple frameworks for each platform ie. iOS, tvOS, watchOS, macOS and instead build just one. This is great, as this greatly simplifies dependency management when scaling towards multiple platforms.

Carthage

Carthage is a dependency management tool that essentially builds dependencies as frameworks for you and leaves it up to you to decide what to do with them afterwards. Where as Cocoapods directly integrates them into your project, making it almost frictionless when using third-party libraries.

However, unlike Cocoapods, Carthage generates these frameworks as as stand-alone which are located in your Carthage/build folder. Previously, adding a framework like Alamofire in your Cartfile using the command carthage update Alamofiregenerates the following paths:

Carthage/Build/iOS/Alamofire.framework
Carthage/Build/watchOS/Alamofire.framework
Carthage/Build/macOS/Alamofire.framework

However, when building the latest .xcframework like so carthage update Alamofire --use-xcframeworks will generate a single path:

Carthage/Build/Alamofire.xcframework

Remote Caching

There isn’t much tooling during this time of writing that allows us to remote cache these frameworks (and even so pre-iOS 14). When .xcframework support came out, practically none of the existing tooling were ready for this sudden change. It was difficult, to say the least, to manage iOS build pipelines that have existing caching move towards iOS 14 without running into binary issues, so our team at Shred was forced to in iOS 13 as existing tooling allowed us to continue our day to day. However, as all startup developers know, time is of the essence, so we needed to figure out a way to move up the version, get past all these binary issues and stalled build-to-device times, and set up a reasonable adoption plan to move towards a stable developer cadence.

Enter Punic

We built Punic as a response to these times, there was definitely a need to fix our build pipeline but without support for remote caching for .xcframeworks we were essentially stuck in iOS 13 land.

This internal-tooling, now public, allowed our team to adopt the new change by Apple as well as being able to maintain our level of speed during our build pipelines via remote caching.

To install,

brew brew tap summerlabs/homebrew-punic
brew install punic

And then after building all your .xcframeworks into your Carthage/Build folder and creating a Punfile to setup the remote caching configuration simply run,

punic upload

Awesome. Your .xcframeworks will be zipped up into your AWS S3 bucket and whenever your local repository needs it’s latest dependencies, whether it is from a new clone or directly in your CI/CD’s build pipeline script, run

punic download

And that’s it.

Remote caching for Apple’s new .xcframeworks 🚀

The project was made in Rust as well and if you find any issues please feel free to create one or contribute if you feel the need to. Thank you!

--

--

Andrew Aquino
Shred Engineering

Entrepreneur / Senior Full-Stack Software Engineer