iosswiftxcodeswift-package-managerxcframework

Swift library package produces empty archive


I'm trying to produce a .xcframework compiled version of my Swift library package. With an Xcode managed library target, I can archive the scheme and the resulting framework could be embedded and linked by another project. However, when I attempt to archive a pure swift package (that is to say, the dir containing the Package.swift file is what's open in Xcode, there is no .xcodeproj), the resultant archive is empty, devoid of any build products.

This is reproducible both in my project and also with a brand new Swift library package (obtained by running swift package init --type library). It's reproducible whether I archive through Xcode's gui or with xcodebuild archive -scheme 'MyPackage' -destination "generic/platform=iOS" -archivePath archive.xcarchive BUILD_LIBRARY_FOR_DISTRIBUTION=YES SKIP_INSTALL=NO.

The latter produces a binary, but no module map or any of the resources included in the library. The former produces a completely empty archive.

Swift Package Manager supposedly supports the distribution of pre-compiled libraries via binaryTarget, which I have working just fine (with a framework built by an xcodeproj) - the distribution part isn't the issue, it's the actual building.

I should state that when the library package is referenced as a dependency in source form, all the symbols are perfectly accessible and everything works as expected.

In summary, how do I compile a SPM library package to a framework? There is next to no documentation on this anywhere and I'm at a loss.


Solution

  • There isn't yet any supported way to do it, according to https://developer.apple.com/forums/thread/741100, which came out of the (3-year-old) https://forums.swift.org/t/how-to-build-swift-package-as-xcframework/41414. There's more information at https://forums.developer.apple.com/forums/thread/655768.

    This manual solution does seem to work for products declared as .dynamic, but requires some scripting, or else the creation of an Xcode project container.