Cache Swift Package Manager Dependencies Add via Xcode

Are there any suggestions for how to setup a reliable cache for Swift Package Manager dependencies that are managed directly in Xcode?

Screenshot 2020-07-08 10.09.07

Tracking the lock file ( [appName] .xcodeproj/project.workspace/xcshareddata/swiftpm/Package.resolved) results in frequent build timeouts on Circle. However not tracking the lock file would be non-deterministic as to the version resolved.

Any suggestion would be appreciated as I have not been able to find a good method for cacheing the resolved dependencies as they seem to only be resolved within the DerivedData folder which isn’t easily/reliably shared.

1 Like

Is switching to cocoapods an option?

here is an article on caching SPM dependencies in CI swift package manager and how to cache it with ci

This caches the source but not the built frameworks.

I recently tried to switch from Carthage to SPM and found that my CI build times tripled because it needed to rebuild all my dependencies every time. If anyone has figured out a good caching option to avoid this, I’d love to hear it. Using the source caching option posted above cut the time down slightly, but it’s still rebuilding the libraries.

Did you find any good results? I’m also looking for a way to move from Carthage to SPM and cache the builds on my CI (I’m using bitrise)

We have a working SPM setup that caches the SPM sources but I’ve not found any reliable way to cache Xcode build artefacts of any description unfortunately.

For now the best we’ve managed is caching based off the checksum of our Package.resolved file. The steps are roughly:

  1. Checkout source.
  2. Restore SPM source cache.
  3. Resolve dependencies in case anything has changed - we do this with an explicit xcodebuild -resolvePackageDependencies step (this is also a good opportunity to remove any bloat from the SPM sources - some sources include large binary files that you might not need).
  4. Persist the updated SPM source cache.

When you actually build/test your app, you need to make sure you pass the -clonedSourcePackagesDirPath option to point at your SPM source cache and -disableAutomaticPackageResolution.

agree. Tried the same. At least in my case, it’s the building that takes more time, not fetching sources.