I'm unsure if this is an Xcode-specific bug or a bug with SPM, but I'm trying out the new beta to see if the new support for dynamic linking of SPM dependencies would solve an issue I've been having trying to move some unit testing support code into a package library.
This Package.swift demonstrates my scenario - CasePaths is the actual dependency I'm having trouble with but I don't know if the issue lies with that or elsewhere:
let package = Package(
name: "MyLibrary",
platforms: [.iOS(.v13), .macOS(.v10_15)],
products: [
.library(
name: "MyLibrary",
targets: ["MyLibrary"]
),
.library(
name: "MyLibraryTestHelpers",
targets: ["MyLibraryTestHelpers"]
)
],
dependencies: [
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "0.1.2")
],
targets: [
.target(
name: "MyLibrary",
dependencies: [
.product(name: "CasePaths", package: "swift-case-paths")
]
),
.target(
name: "MyLibraryTestHelpers",
dependencies: ["MyLibrary"] // also uses XCTest but I think that's fine?
),
.testTarget(
name: "MyLibraryTests",
dependencies: ["MyLibrary"]
)
]
)
This is a local package alongside an iOS app target in an Xcode workspace. The app target (MyApp
) has a dependency on MyLibrary
and the app's unit test bundle (MyAppTests
) has a dependency on MyLibraryTestHelpers
. I was never able to get this to work in previous Xcode versions due to the diamond dependency problem and I'm hoping the new dynamic linking feature in 12.5b2 solves this but I can't even get that far.
Here's what does work:
- I can use the
MyLibrary
Xcode scheme to successfully compileMyLibrary
in isolation. - I can use the
MyLibrary
Xcode scheme to successfully compile and run all of the tests (in theMyLibraryTests
test target) forMyLibrary
. - I can build my app target using the app's scheme - it builds all of its dependencies, including
MyLibrary
without issue.
What I cannot do is compile MyAppTests
- it immediately fails trying to compile MyLibrary
(which it implicitly depends on through its dependency on MyLibraryTestHelpers
) with the error, No such module "CasePaths"
.
I don't understand why it cannot find the CasePaths
module when trying to compile MyLibrary
in this scenario, when it compiles fine in all other scenarios.
While trying to get this work I also frequently ran into "The build system has crashed, please re-open your workspace" errors but I put this down to general beta instability.