A simple Command Line Tool to create XCFrameworks by wrapping xcodebuild.
swift-create-xcframework is a very simple tool designed to wrap
xcodebuildand the process of creating multiple frameworks for a Swift Package and merging them into a single XCFramework.
On the 23rd of June 2020, Apple announced Xcode 12 and Swift 5.3 with support for Binary Targets. Though they provide a simplified way to include Binary Frameworks in your packages, they did not provide a simple way to create your XCFrameworks, with only some documentation for the long manual process. swift-create-xcframework bridges that gap.
Note: swift-create-xcframework pre-dates the WWDC20 announcement and is tested with Xcode 11.4 or later, but should work with Xcode 11.2 or later. You can include the generated XCFrameworks in your app manually even without Xcode 12.
Inside your Swift Package folder you can just run:
By default swift-create-xcframework will build XCFrameworks for all library products in your Package.swift, or any targets you specify on the command line (this can be for any dependencies you include as well).
Then for every target or product specified, swift-create-xcframework will:
.frameworkfor each supported platform/SDK.
This process mirrors the official documentation.
Let's use an example
var package = Package( name: "example-generator", platforms: [ .ios(.v12), .macos(.v10_12) ], products: [ .library( name: "ExampleGenerator", targets: [ "ExampleGenerator" ]), ], dependencies: , targets: [ ... ] )
By default swift-create-xcframework will build
ExampleGenerator.xcframeworkthat supports: macosx, iphoneos, iphonesimulator. Additional
.libraryproducts would be built automatically as well.
You can narrow down what gets built If you omit the platforms specification, we'll build for all platforms that support Swift Binary Frameworks, which at the time of writing is just the Apple SDKs: macosx, iphoneos, iphonesimulator, watchos, watchsimulator, appletvos, appletvsimulator.
Note: Because only Apple's platforms are supported at this time, swift-create-xcframework will ignore Linux and other platforms in the Package.swift.
You can specify a subset of the platforms to build using the
--platformoption, for example:
swift create-xcframework --platform ios --platform macos ...
You can build your XCFrameworks with support for Mac Catalyst by specifying
--platform maccatalyston the command line. As you can't include or exclude Catalyst support in your
Package.swiftwe don't try to build it automatically.
Because we wrap
xcodebuild, you can actually build XCFrameworks from anything that will be mapped to an Xcode project as a Framework target. This includes all of the dependencies your Package has.
To see whats available:
swift create-xcframework --list-products
And then to choose what to build:
swift create-xcframework Target1 Target2 Target3...
By default it builds all top-level library products in your Package.swift.
Because of the low-friction to adding command line options with swift-argument-parser, there are a number of useful command line options available, so
--helpshould be your first port of call.
swift-create-xcframework provides a
--zipoption to automatically zip up your newly created XCFrameworks ready for upload to GitHub as a release artefact, or anywhere you choose.
If the target you are creating an XCFramework happens to be a dependency, swift-create-xcframework will look back into the package graph, locate the version that dependency resolved to, and append the version number to your zip file name. eg:
If the target you are creating is a product from the root package, unfortunately there is no standard way to identify the version number. For those cases you can specify one with
Because you're probably wanting to distribute your binary frameworks as Swift Packages
swift create-xcframework --zipwill also calculate the necessary SHA256 checksum and place it alongside the zip. eg:
swift-create-xcframework includes a GitHub Action that can kick off and automatically create an XCFramework when you tag a release in your project.
The action produces one zipped XCFramework and checksum artifact for every target specified.
Note: You MUST use a macOS-based runner (such as
macos-latest) as xcodebuild doesn't run on Linux.
You can then take those artifacts and add them to your release.
An incomplete example:
name: Create Release
Create XCFramework when a version is tagged
on: push: tags:
jobs: create_release: name: Create Release runs-on: macos-latest steps:
- uses: actions/[email protected] - name: Create XCFramework uses: unsignedapps/[email protected] # Create a release # Upload those artifacts to the release
You can install using mint:
mint install unsignedapps/[email protected]
git clone https://github.com/unsignedapps/swift-create-xcframework.git cd swift-create-xcframework make install
Either should pop the swift-create-xcframework binary into
/usr/local/bin. And because the
swiftbinary is extensible, you can then call it as a subcommand of
swift create-xcframework --help
Please read the Contribution Guide for details on how to contribute to this project.
swift-create-xcframework is available under the MIT license. See the LICENSE file for more info.