The steps to create an xcframework out of a collection of Swift sources are:
arm64-apple-ios-simulator
). The result of this step is a framework bundle, ex. SwiftyBeaver.framework
.xcodebuild -create-xcframework
.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.
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:
swift build --target A ...
to build the target. Build artifacts are stored under .build/debug
.libtool
from .o
files in .build/debug/A.build
:
libtool -static -o A.framework/A .build/debug/A.build/**/*.o
.build/debug/A.build
and .build/debug/Modules
to A.framework/Modules
.module.modulemap
under A.framework/Modules
so that this framework is visible to ObjC code.A.framework/Headers
..build/debug/A_A.bundle
) to the framework bundle.xcodebuild -create-xcframework \
-framework arm64-apple-ios-simulator/SwiftyBeaver.framework \
-framework arm64-apple-ios/SwiftyBeaver.framework \
-output SwiftyBeaver.xcframework