xccache

< Knowledge Base

Under the Hood: Packaging as an xcframework

The steps to create an xcframework out of a collection of Swift sources are:

There are some tricky actions in step (1) so that the framework bundle meets requirements in step (2). For example, in case of Swift frameworks, xcodebuild -create-xcframework requires a swiftinterface in the swiftmodule.

Creating a Framework Slice

By default, building a Swift package target (with swift build) does not produce a .framework bundle. We have to package it outselve from .o files, headers, swiftmodules, etc.

A.framework
  |-- A (binary)
  |-- Info.plist
  |
  |-- Headers /
  |-- Modules /
        |-- module.modulemap
        |-- A.swiftmodule /
              |-- arm64-apple-ios-simulator.swiftinterface
              |-- arm64-apple-ios-simulator.swiftdoc
              ...

Steps to create a framework:

Creating an xcframework from Framework Slices

xcodebuild -create-xcframework \
  -framework arm64-apple-ios-simulator/SwiftyBeaver.framework \
  -framework arm64-apple-ios/SwiftyBeaver.framework \
  -output SwiftyBeaver.xcframework