Package Names in Swift 5.2

I mostly just confused myself because I was off on a rabbit trail.

Until 5.1, SwiftPM had a bug where you needed to call the package by its last URL component instead of its declared name. (Hence the first example above.) I knew it had been fixed in master, but I wasn’t sure which release it would end up in. So when I updated to 5.2, the first thing I did was experiment to see which I needed to be using now. The old was now correctly failing (it was relying on a bug), but since I hadn’t updated the tools‐version yet, SE‐0226 had not even entered my mind. I had already forked several repositories to “repair” their names and make them usable by the time I saw @Mordil’s post and did a facepalm. (Thanks for replying so quickly, @Mordil)

If I weren’t tracking the development of SwiftPM so closely, I likely wouldn’t have made the mistake in the first place. I don’t think it will confuse the average user, but this thread can stick around in case it does. The complete solution is this:

// Add the name parameter to the package dependency:
.package(
  name: "SwiftSyntax",
  url: "https://github.com/apple/SwiftSyntax",
  .exact(Version(0, 50200, 0)
)
// And use the name in the target dependency:
.product(name: "SwiftSyntax", package: "SwiftSyntax")
2 Likes