Reusing spm code elsewhere

There is a bunch of code inside this project which is potentially really useful outside of it — for example, I've been using just the Version struct (from PackageDescription) in my macOS app.

However, I'm wondering if there's a clean way to access it? At present I'm cloning the whole spm repo, and dragging just the two code files I need from the swift-package-manager/Sources/PackageDescription folder into Xcode. I rather wish Version was a separate project, becoming a dependency of spm.

Also, sorry if this is documented already, but why are there so many version-related structs? I count at least 3 or 4 which at a glance look pretty similar.

They could pull those dependencies out into their own packages and publish them, but then spm depends on itself to build, which would be weird. Perhaps once the development dependency feature is integrated, spm could use that feature but allow everyone else to pull the packages normally.

What we really need is an officially hosted dependency repo a la CocoaPods, but apparently Apple hosting anything is the most complex thing they do, so I'm not holding my breath. That would solve the problem nicely, as they could just publish versions of the libraries periodically, and they'd be separate from whatever development spm is doing.

You could generate an Xcode project and then add it as a subproject (you'll need to add some extra flags because of the clibc target) but if you only need Version, I am not so sure if that way is better. We do plan to move the infrastructure related code into a separate repository.

Please note that this is not official Apple API and we will add/remove things depending on the needs of the build system projects.

Thats due to a technical issue that no one gotten around to solve yet. I would recommend using Utility/Version.swift and not PackageDescription/Version.swift.

We do plan to propose an index in the future!

1 Like

Thanks for the comments.

Personally I think spm depending on itself to build would be cool :D

@Aciid — I attempted to move to Utility/Version.swift as suggested, but that even more clearly illustrated my original problem; I wasn't able to get it working due to the chain of dependencies it requires. I included several but didn't reach the end of the chain, so decided I wasn't likely to succeed without learning more deeply about the internals of the rest of spm. Instead I found a package on Github which has "borrowed" considerably from spm's version code, but modified to be standalone.

For several reasons, for example its https://github.com/apple/* location, my perception is that SPM's code is likely to be "somewhat canonical", at least in terms of things like the version code I'm attempting to borrow, and that it's likely to be supported & updated for a long time.

All of which makes it rather an attractive source from which to steal and borrow code :) ...none of these factors being relevant to the core purpose of the project, of course!

Cool! Out of curiosity, can you share this package's link?

Right, it may be the case that things like Version will be supported and present in SwiftPM's codebase for a long time but it is important to realize that it is not official API like Swift's stdlib, Foundation, Dispatch etc.

The package is https://github.com/trifia/LXSemVer — it's possible I've overstated its borrowings from SPM, though it seems pretty nicely compatible.

I hear you re SPM's codebase not being official API.

1 Like
Terms of Service

Privacy Policy

Cookie Policy