Offline development with SPM?

The way that we specify dependencies in Package.swift, with URLs to a git repository (frequently Github) or paths to a local file, work great when the specified resource is available. But what happens when the network goes down?

When I was working with an entirely Java ecosystem, we addressed this with a caching proxy for artifacts, so that when a road crew accidentally cut our network cable and our whole office was without internet for a day, we didn't lose a day's work -- clean builds could still happen, since our builds didn't go to maven central but to our local artifact repository.

It seems to me that this approach wouldn't work with SPM, since each dependency is specified by a fully qualified URL, and of course our direct dependencies may pull in transitive dependencies which are themselves specified with fully qualified URLs.

But it also seems to me that I'm far from the smartest guy in the room, so someone else must have noticed this already. What's the answer? Is there some tool that you can point at a Package.swift and have it pull in the full dependency tree and store it somewhere locally, so that if you then delete your project's .build directory and run swift build the dependencies will be fetched again, but from the local directory?

1 Like

SwiftPM has a cache stored at (by default) ~/.swiftpm/cache that it will pull dependencies from when there's none in the local build folder. I don't know how it behaves with no network connection but some of the basic plumbing is already there. I believe mirrors and proxies have already been pitched on here and are related as well

I believe using mirroring is indeed the current answer to this and in the future it could be a custom registry.

1 Like
1 Like

@SDGGiesbrecht I tried it, but Xcode Project projects are not supported, currently only SPM projects are supported. Swift package config is not available in Xcode factories.

Do you mean Xcode disobeys existing configurations, or do you just mean Xcode lacks an interface for setting a configuration up? (Either way, you will ultimately have to take it to the Feedback Assistant, because it is a problem with Xcode, not with Swift.)

@SDGGiesbrecht

Xcode only supports the xcodebuild command, not the swift package command, and cannot be configured mirror through swift package config