I’m trying to understand how the package access modifier works with binary targets in Swift Package Manager.
Here’s a simplified example of my Package.swift:
import PackageDescription
let package = Package(
name: "MyLib",
platforms: [
.iOS(.v13),
],
products: [
.library(
name: "MyLib",
targets: ["MyLibWrapper"]
),
],
dependencies: [],
targets: [
.binaryTarget(
name: "MyLibCore", // package_name: MyLibInternal
path: "Frameworks/MyLibCore.xcframework"
),
.binaryTarget(
name: "MyLibAuth", // package_name: MyLibInternal
path: "Frameworks/MyLibAuth.xcframework"
),
.target(
name: "MyLibWrapper",
dependencies: [
.target(name: "MyLibCore"),
.target(name: "MyLibAuth"),
],
packageAccess: true
)
]
)
When using this package in another project that has the same SWIFT_PACKAGE_NAME (MyLibInternal), I get the following error:
Module 'MyLib' is in package 'MyLibInternal' but was built from a non-package interface;
modules of the same package can only be loaded if built from source or package interface:
.../MyLibCore.framework/Modules/MyLibCore.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface
However, if I look inside the .xcframework, there is a arm64-apple-ios-simulator.package.swiftinterface alongside the private interface. So it seems SwiftPM is choosing the .private.swiftinterface even though a .package.swiftinterface exists.
So my question is:
Are binary targets fundamentally unable to use the package access modifier (and package-level visibility), or is there some way to build or configure a binary target so that SwiftPM treats it as having a package interface?
Any insight into whether this is by design or if there’s a possible workaround would be greatly appreciated.