Implement an Install Command for the Swift Package Manager


(Caleb Kleveter) #1

As it is, adding dependencies to your project is a bit of a pain. You go to the dependencies repo, copy the Git URL, check to see what the latest version is, go back to your project, add the dependency to your manifests dependencies array, run swift package update, generate an Xcode project or try to build, realize you forgot to add the dependency to your target(s), add it to the target(s), regenerate your Xcode project (if it applies),
and now it works! To sum it up, it requires too much back-and-forth work.

I think it would make sense to have an install command that works similarly to Go:

go get github.com/user/repo
swift package install github.com/user/repo

This would add the dependency to the manifest and one or more of its products to any of the project’s targets.

Any ideas, thoughts, objections, or suggestions?

Related:


(Tanner) #2

I would really love to see this feature!

The hard part about this command would seem to be helping the user determine which version requirement they should use. I see two parts to this problem:

  • Discovering which available versions are compatible with their package manifest (maybe none)
  • Offering available levels of version specificity to the user. Do they want to restrict to this major release? Maybe just this minor release or even the exact release? What is the default?

(Harlan Haskins) #3

We could use the latest git tag, if none is provided, have a --branch <branch> flag if you want to just pick HEAD of a given branch, and have an @<tag> suffix on package names if you want a specific tag?


(Tanner) #4

If that is the latest compatible git tag, I’d support it +1.

There’s obviously a lot more you could do in the way of some user-interaction (providing a list of available options, etc). But I think that’s better handled by convenience CLIs anyway.


(Ankit Aggarwal) #5

Yeah this will be a super nice addition but unfortunately we can’t mechanically edit Package.swift file right now.


(Tanner) #6

Hmm…serializing Swift seems like a very challenging problem.


(Ankit Aggarwal) #7

I hope we can leverage sourcekit to achieve that. I listed that as an idea for GSoC. https://swift.org/project-ideas/


#8

This would be a great addition to the Swift Package Manager.
Personally I would slightly favour add as command. Though perhaps install is more common amongst package managers.

Being able to use something like …

$ swift package add github.com/foo/bar@1.0.0 -t TargetName

… would be a real time saver. This would add the Bar dependency (version 1.0.0 specifically) only to the target named TargetName.


(Xiaodi Wu) #9

For bikeshedding precise designs, I think we can safely wait until an actual proposal or pitch makes it to Swift Evolution :)


(Tanner) #10

Discussion continued in SwiftPM slack and it quickly became apparent that this inability to easily install packages is a symptom of a much bigger problem with the Package.swift manifest.

I created a proposal that I think will solve the problem presented here by @calebkleveter and many other problems: Spm static dependencies