Binary Swift Package Chicken and Egg Situation

So, I've been following along the video on Distribute binary frameworks as Swift packages, but now I'm sort of stuck.

I have my Swift Package that works fine when used as a source package, which I want to ship as a binary now.

The video says, I'm supposed to add a target:

Code Block swift
import PackageDescription
let package = Package(
    name: "Test",
    defaultLocalization: "de",
    platforms: [
        .iOS(.v13)
    ],
    products: [
        .library(
            name: "Test",
            targets: ["Test"]
        ),
    ],
    dependencies: [
    ],
    targets: [
//        .target(name: "Test")
        .binaryTarget(
            name: "Test",
            url: "https://static.looc.io/Test/Test-1.0.0.xcframework.zip",
            checksum: "9848327892347324789432478923478"
        )
    ]
)

but, the xcframework is what I am trying to build, don't have an xcframework yet?

With the above, if I run:

Code Block bash
[konrad@iMac-2 Source]$ xcodebuild archive -workspace Test -scheme Test \
-archivePath "tmp/iOS" \
-destination "generic/platform=iOS" \
SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES

I get the error
Code Block bash
xcodebuild: error: Could not resolve package dependencies:
  artifact of binary target 'Test' failed download: invalid status code 403

Replies

If I comment out the .binaryTarget and only use the .target(name:) the bash output is ARCHIVE SUCCEEDED [58.086 sec] but then if I look into the archived file, it has no *.framework inside it.


To create the XCFramework, you need to use an Xcode project to build and package the binary as an XCFramework. Once you have the XCFramework, then you can use a Swift package as the distribution vehicle.

To learn how to build an XCFramework, please consult Create an XCFramework and Binary Frameworks in Swift.
Mhm, so I thought according to the Swift package Manager Team an Xcode project is not necessary to build an xcframework based on a Swift Package..
boris is also referencing the same demo example he did in the WWDC video Distribute binary frameworks as Swift packages from 2020, so I thought this is the latest status compared to the video Binary Frameworks in Swift from 2019.

As a swift package, my project automatically gets an extension that provides the Bundle.module extension, e.g.
Code Block swift
let string = NSLocalizedString(self, tableName: nil, bundle: .module, value: "", comment: "")

which is no longer available if I wrap the code into an xcodeproj.

I thought based on the above mentioned github issue, the xcodeproj way is no longer necessary.