Is it possible to produce an XCFramework from a Swift Package with dependencies?
Asked Answered
D

1

8

I want to be able to take an internal SPM package, which depends on several other internal (and one external) SPM packages, and compile it into an XCFramework, using a series of xcodebuild like you would for a framework project. For example, I have PackageB, which references PackageA, and I'm trying to build PackageB.xcframework. The first step would be:

xcodebuild -scheme PackageB -destination "generic/platform=iOS" -configuration Release ARCHS="arm64" BUILD_DIR="./Build

The tool's output indicates that the dependency packages are being resolved, but they are then not recognized by the compiler (i.e. code in PackageB which references PackageA will not compile because PackageA is unknown at that point).

Thanks for any pointers.

Darlleen answered 17/5, 2022 at 15:8 Comment(1)
If your package has other swift packages as dependencies this will be difficult. It's something I'm researching myself at the moment. I found the following blog post discussing it: kean.blog/post/xcframeworks-caveats. Also, this post has some information about it as well: forums.swift.org/t/how-to-build-swift-package-as-xcframework/…Gann
T
4

You can create xcframework from swift package by using swift-create-xcframework command line tool, there is also GitHub action available for this.

If you don't want to use this tool, you can generate Xcode project by using swift package generate-xcodeproj command:

OVERVIEW: Generates an Xcode project. This command will be deprecated soon.

USAGE: swift package generate-xcodeproj

OPTIONS: --xcconfig-overrides Path to xcconfig file --output Path where the Xcode project should be generated --legacy-scheme-generator Use the legacy scheme generator --watch Watch for changes to the Package manifest to regenerate the Xcode project --skip-extra-files Do not add file references for extra files to the generated Xcode project --version Show the version. -h, -help, --help Show help information.

and then create xcframework with the generated Xcode project.

Towage answered 23/5, 2022 at 17:0 Comment(1)
swift package generate-xcodeproj is not availableScansion

© 2022 - 2024 — McMap. All rights reserved.