SwiftPM package from 3rd party repo

Let's say there's a repo that technically would build with SwiftPM. But there's no sense in adding the Package.swift file to that repo, or the owners won't accept it.

Is there a way to build that repo with SwiftPM, assuming the source is on a public git repo?

See https://cocoapods.org/pods/leveldb-library for an example in CocoaPods. Note how the repo itself doesn't have a podspec but there's a way to get the package and build it.

A fork is one way.

leveldb-library is one in particular we're working on for Firebase: https://github.com/google/leveldb/pull/818

Hi Paul!

I was using LevelDB as an example - personally I'm more curious about ReactiveObjC which seem to not want to add a manifest.

SwiftPM will check out Git submodules for anything it resolves as a dependency. That means if you create a separate repository with only a manifest and a submodule, you can use it as a package without altering the original repository in any way. (You will still have to manually check out the submodule when your package is at the top level. This is because top‐level packages are allowed to not even have source control.)

Just be careful that you don’t add the same source as a submodule in more than one place in the package graph, because SwiftPM will not be able to unify them. If that happens, you will have all sorts of name clashes and duplicate symbols (particularly if it includes C code). This is why adding a manifest to the repository itself is usually preferable over submodules.

2 Likes

Another example (of adding Package.swift to a fork) is apple/swift-cmark.