I'm having a problem defining the Package.swift
file for my binary closed-source dynamic framework which depends on a number of non-binary open-source dynamic frameworks.
My Package.swift
file looks like this:
// swift-tools-version: 5.8
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
import Foundation
let package = Package(
name: "MyLibrary",
platforms: [
.iOS(.v12)
],
products: [
.library(
name: "MyLibrary",
targets: ["MyLibraryWrapper"]
),
],
dependencies: [
.package(url: "<dependency-url>", branch: "master"),
],
targets: [
.target(
name: "MyLibraryWrapper",
dependencies: [
.target(name: "MyLibrary"),
.product(name: "<dependency-product-name>", package: "<dependency-package-name>")
],
path: "MyLibraryWrapper"
),
.binaryTarget(
name: "MyLibrary",
url: "<url-to-xcframework-zip>",
checksum: "<checksum>"
)
]
)
The package builds successfully. However, when I add it to any app, I get the following runtime error:
Library not loaded: @rpath/<dependency-product-name>.framework
The only workaround I know is to add type: .dynamic
to the library(name:type:targets:) declaration in the Package.swift
file of each of my framework's dependencies. This requires me to fork each of my framework's dependencies and maintain the forks. That's not something I'm keen on.
Is there is a better, simpler solution to this problem?
Notes
- I need to declare the
MyLibraryWrapper
target in myPackage.swift
file because the binaryTarget(name:url:checksum:) method does not offer adependencies
parameter. - The
MyLibraryWrapper
directory which theMyLibraryWrapper
target declares as itspath
contains a single empty source file and nothing else. - The non-binary dynamic frameworks which my binary dynamic framework depends on do not specify an explicit
type
value in theirPackage.swift
files based on Apple's recommendation in the library(name:type:targets:) method documentation: "It’s recommended that you don’t explicitly declare the type of library".