Bug with .binaryTarget in Swift Packages with Xcode?

I'm building an App's test target with xcodebuild. The test target includes tests from a Swift Package, which has an XCFramework .binaryTarget—SwiftProtobuf.xcframework. We have used a symlink to link from a directory inside the Swift Package's directory, to the XCFramework, since you can't include a .binaryTarget from outside the Package's own directory structure (which isn't a bug, but nonetheless, is really dang annoying).

The build itself will encounter the error:

error: no such module 'SwiftProtobuf'
import SwiftProtobuf

This error happens BEFORE we get to this build step:

ProcessXCFramework /REDACTED/TensorManifold/lib/SwiftProtobuf.xcframework 
(in target 'TensorManifold' from project 'TensorManifold')

The build command that was run:

set -o pipefail && env NSUnbufferedIO=YES xcodebuild \
 -workspace REDACTED.xcworkspace \
 -scheme AllUnitTests -configuration Debug_Testing \ 
 -derivedDataPath /private/tmp/build/REDACTED/ios/fastlane/output/derivedData \
 -destination 'platform=iOS Simulator,name=iPhone 7,OS=14.3' \
  clean build-for-testing

Here is what our Package.swift looks like:

import PackageDescription

let package = Package(
    name: "TensorManifold",
    platforms: [
    products: [
            name: "TensorManifold",
            targets: ["TensorManifold", "SwiftProtobuf"]
    dependencies: [
    targets: [
            name: "TensorManifold",
            dependencies: ["SwiftProtobuf"]
            name: "SwiftProtobuf",
            path: "lib/SwiftProtobuf.xcframework" // this is a symlink
                                            // it builds just fine in Xcode

Another bizarre thing about this bug is that it seems to be quite intermittent. Our CI system has several fastlane "lanes" that each get built on a separate Mac. For reasons unknown, sometimes they will fail with the above-mentioned error, where SPM acts like like SwiftProtobuf doesn't exist:

error: no such module 'SwiftProtobuf'
import SwiftProtobuf

I can assure you in all these cases, SwiftProtobuf.xcframework does in fact exist, and the path "lib/SwiftProtobuf.xcframework" is a valid path (it's a symlink to where the actual XCFramework is kept).

Can anyone think of a reason why this should fail intermittently like that?

Reading further, it seems there have been a lot of problems with using .binaryTarget in SPM, such as Xcode not signing them, or Xcode not copying them into the build folder before trying to compile the code in the module, etc.

It has started to occur to me—what we need is a way to list an XCFramework in the "dependencies" section of a Swift package. "Target" should only be used for when the binary is published as part of your package.

It seems .binaryTarget was created as a way to let someone wrap an XCFramework inside of a Swift Package so they can publish a closed-source package, like how Google now publishes Firebase.

But what we users need, is a way to link an XCFramework (that doesn't have a Swift package) into a locally-declared Swift package (that's not published anywhere and which we're basically just using as a way to avoid using .xcproj files to organize code in our app).


I'm running into this exact problem now. Wondering if you found any resolution. SPM and binaryTarget works great locally, but not on CI.

For some more context, I've found that my build locally with the same command line works for 12.5 but not 12.4. Our CI is 12.4 (Github Actions). However, using Xcode visually works with 12.4. I haven't figured out a reasonable workaround yet, but hoping we can either get 12.5 preview for Github, or something else. Otherwise kind of stuck currently.

I found that it works for 12.5.1 but not for 13.0... this is a real problem looks like

Terms of Service

Privacy Policy

Cookie Policy