I know that Xcode doesn't have explicit support in the UI for Package Registries, but can use packages referenced by ID if the registry is set up through the CLI.
I also see that xcodebuild has support for SCM to registry transformation (resolving and downloading packages through a registry, even if the packages are referenced using their Github URLs) through options like -defaultPackageRegistryURL and -packageDependencySCMToRegistryTransformation. Is there any way to achieve the same thing in Xcode itself?
Are you familiar with NPM, PyPI, or homebrew (sorta)? Registries are like that. Instead of having to clone the whole repo of the package you're pulling in, SPM can just download a zip file.
This is not yet supported in Xcode directly; but you can handle this with an environmene variable in your scheme:
-IDEPackageDependencySCMToRegistryTransformation={the same value supplied to the CLI}
I'm also struggling with adding a package registry to an xcode project. I made a little progress using IDEPackageDependencySCMToRegistryTransformation , but I need to set the scope and i'm not sure how it should be done.
Equivalent to swift package-registry set --scope <scope> <registry-url>
Not sure if this helps you to find a solution. Last time I played with registries I made it work by editing the content of the .swiftpm folder in the xcode project bundle so it contains the changes that you usually do via the swift package commands.
I'm finding it very hard to get it working reliably even in a package, I'm never sure what combination and order of cleaning caches, running swift commands and logging in get's it to work even on a package.
In my case, I'm trying to get it to work with jfrog Artifactory JFrog Help Center
Adding the registries json file from a working package to the xcworkspace is indeed what got it working for me, thanks! (Or at least progressed, the package is now downloading to the cache, it's failing for another reason...)
I initialy got a git shell error 128 during package resolution, but this just required the swift package-registry login <url> command to be run again to fix it.
Found my issue, and as it was still related to the registry, I'll add it here.
I was using a method similar to how amazon analyze the root of the package to find the binaries and add the products and targets in the Package.swift file when they're working locally.
In all other circumstances this seems to work, except when pulled through the package registry, when it would fail to add the products and targets, probably #file was not working correctly, I'm not sure how I would go about debugging it.
This was handy workaround as we're building a c++ library with multiple layers of dependencies, and not having to update the Package.swift with changes was useful.
Likely I will now figure out something with swift code gen when building the package.
This continues to be challenging. Some further issues I have resolved trying to get this to work in an XCode project.
The package I'm vending through the package registry is one depended on by higher level packages, so the project doesn't have a direct reference to the low level package, it is only through the high level packages.
I was working with these high level packages added as local packages to the project while I tried to get everything working. using a branch in each repo (let's say package-registry-update)
Now, I got everything working like that, I removed the local references to the high level packages from the project, and told them all to instead resolve to the package-registry-update branch of the repos in github.
This starts causing errors during package resolution of the project with errors like could not find a branch named βpackage-registry-updateβ in git@github.com:org/high-level-package-1.git
Thinking I'd hadn't pushed them or somehow had some weird security setting, I messed around in git for ages, but couldn't find anything.
So, thinking maybe If I still had a local package that had the package registry as a dependency, it might solve the issue, which indeed it did. I think this is the solution described at the end of this post : What is Swift-Package-Registry? β Lukas Pistrol
However, I tried that earlier and it simply wouldn't work, only adding the config file in the .swiftpm directory did anything.
I feel these problems are due to the multiple levels of dependency I'm running, and the multiple steps it takes to work on packages in an xcode project, but maybe someone will find this useful in the future.
Something I was not aware of. When you use the --global option for swift package-registry set it places the registries.json file in ~/.swiftpm/configuration/
This directory is an alias to one of the spm caches, and if you clean out your caches, you lose your global configuration. I was not aware of this and I think this might have caused me much grief.
I would have expected that xcodebuild -resolvePackageDependencies -packageDependencySCMToRegistryTransformation useRegistryIdentityAndSources -defaultPackageRegistryURL {registry-url} would be the equivalent of swift package --replace-scm-with-registry --default-registry-url {registry-url} but while the swift package ... command does install the packages from the registry, xcodebuild still uses source control instead.