Here's a concrete example:
Foo
Playing Foo
, IGListKit Package.swift
excerpts:
products: [
.library(name: "IGListDiffKit",
type: .static,
targets: ["IGListDiffKit"]),
.library(name: "IGListKit",
type: .static,
targets: ["IGListKit"]),
…
targets: [
.target(
name: "IGListDiffKit",
path: "spm/Sources/IGListDiffKit"
),
.target(
name: "IGListKit",
dependencies: ["IGListDiffKit"],
path: "spm/Sources/IGListKit"
),
Bar
In the role of Bar
, in its entirety:
import PackageDescription
let package = Package(
name: "HistoryList",
platforms: [.iOS(.v13)],
products: [
.library(
name: "HistoryList",
targets: ["HistoryList"]),
],
dependencies: [
.package(name: "IGList", url: "https://github.com/Instagram/IGListKit", from: "4.0.0"),
],
targets: [
.target(
name: "HistoryList",
dependencies: [
.product(name: "IGListDiffKit", package: "IGList"),
.product(name: "IGListKit", package: "IGList")
]
),
]
)
Pruned Package
after importing, the Package.swift of Foo
in the Package Dependencies section states only:
let package = Package(
name: "IGListKit",
products: [
.library(name: "IGListKit", targets: ["IGListKit"])
],
targets: [
.target(
name: "IGListKit",
path: "Source"
)
]
)
It seems that Xcode / SPM is pruning the imported package to contain only one of the three libraries in this package. (Initially, the second library's code was missing, one my my syntaxes caused it to be pulled, but the first was not seen. They are now both there, but only one is seen.)
I couldn't determine a syntax to make it bring down both.
Current Error
product 'IGListDiffKit' required by package 'ios-malauzai-history-list' target 'HistoryList' not found in package 'IGList'.
Xcode 15.0 beta (15A5160n)
Additional Thoughts
package(name:url:_:) (and the name
property of Package.Dependency
) has been deprecated, but you need to use the name of the package dependency to use in the specific target dependency.
This leads me to believe there is a newer syntax that this that should be used.
Resolution
Instagram doesn't fully support Swift Package Manager for IGListKit
(There are better solutions than IGListKit, but this is in legacy code. Currently, there are 191 commits between the 4.0.0
tag and the HEAD of the repository; it's been 3+ years since a release was made.)
The problem in this case was that the latest tag (as of Jun 2023) is the 4.0.0
tag, and the version of the Package.swift
file is literally the abbreviated version I was receiving.
Everything worked when I updated, and simplified the description to look at the commit that added the support. (Could have used main
branch, but that will keep changing.)
…
dependencies: [
.package(url: "https://github.com/Instagram/IGListKit", revision: "c9e045c9425a160871a7915260d07a6c273b548d")
],
targets: [
.target(
name: "HistoryList",
dependencies: [
.product(name: "IGListKit", package: "IGListKit"),
.product(name: "IGListDiffKit", package: "IGListKit")
]
),
…
"FooB"
in the dependencies for thetargets
array inBar
. To be clear, I'm not talking about the package dependencies, which you show, but rather thedependencies
further down where you define the target inBar
that usesFooB
. You don't include that section so it's hard to say for sure. – AlaricBar
too, because you declare that packageBar
depends on a package calledFooB
, but you don't have a package calledFooB
.FooB
is a product of the packageFoo
, so you only need the.package(path: "Foo")
. – Alaric