Implement an Install Command for the Swift Package Manager

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
swift package install

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?



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?

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?

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.

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

Hmm....serializing Swift seems like a very challenging problem.

I hope we can leverage sourcekit to achieve that. I listed that as an idea for GSoC. - Project Ideas

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 -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.

1 Like

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

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