cargo icon indicating copy to clipboard operation
cargo copied to clipboard

Add subcommand to download the crate source

Open gsingh93 opened this issue 9 years ago • 28 comments

It would be nice to be able to download the source for a crates.io crate. Currently, I either google the repository name to find the github page, or find the crate on crates.io and find the repository link on the crate page. Not only is this process long, but it also may not always work as some crates may have generic and hard to search names, may be hosted on less popular hosting platforms, or may not have include the repository link in the manifest.

A subcommand would be useful to quickly download the source without running into these issues.

gsingh93 avatar Jul 30 '15 17:07 gsingh93

cc me

withoutboats avatar Jul 31 '15 00:07 withoutboats

How do you think this subcommand should be named? Should it essentially work like git clone?

JanLikar avatar Dec 29 '15 06:12 JanLikar

Maybe cargo source or cargo get-source? I prefer the former but don't feel too strongly about the name.

gsingh93 avatar Dec 29 '15 20:12 gsingh93

@JanLikar yeah I've thought in the past that cargo clone may be a good name for something like this, it could even check out the git repo if it's available or just download the source from crates.io (depending on what's selected)

alexcrichton avatar Jan 11 '16 18:01 alexcrichton

I'm willing to do this, but I would need some guidance. @alexcrichton, would you be my mentor?

JanLikar avatar Jan 11 '16 19:01 JanLikar

Certainly! You'll likely want to start this outside of this repo and use the cargo crate on crates.io Once you've got that you'll do something along the lines of:

You may want to also explore other cargo subcommands to explore how to set up the CLI.

alexcrichton avatar Jan 12 '16 00:01 alexcrichton

Why shouldn't I just work with a copy of the master branch?

JanLikar avatar Jan 12 '16 15:01 JanLikar

@JanLikar Because it is fairly trivial to cargo install an external version so that as soon as you get it written and working, people can immediately use it without having to wait for it to get merged into cargo and proliferate into the version of Rust they use. Also it acts as a sort of stabilization period.

retep998 avatar Jan 12 '16 15:01 retep998

@JanLikar yeah what @retep998 says is right, and we also unfortunately can't have "unstable cargo subcommands" so anything added would be instantly stable, and we may not be ready to commit to this.

alexcrichton avatar Jan 12 '16 17:01 alexcrichton

FYI @JanLikar has since created the cargo-clone for this exact purpose. (I note that here because I was asked about the feature and found that the subcommand is not yet mentioned in this issue.)

lifthrasiir avatar Jun 03 '16 07:06 lifthrasiir

cargo-clone is useful; however, it would also be nice to have a cargo-download that downloads the .crate file, with checksum verification (and optional specification of a version other than the latest).

joshtriplett avatar Jul 24 '16 04:07 joshtriplett

I will give you one example where this would be useful to have directly inside cargo: In CI builds you need some Rust tool and you would like to cache the build of that, so you don't waste minutes building the tool every time. Installing another tool here would defeat the purpose - you still sit through cargo's downloads and compilation into a temporary directory that you cannot cache.

lilianmoraru avatar Dec 21 '17 08:12 lilianmoraru

As there hasn't been any activity here in over 6 months I've marked this as stale and if no further activity happens for 7 days I will close it.

I'm a bot so this may be in error! If this issue should remain open, could someone (the author, a team member, or any interested party) please comment to that effect?

The team would be especially grateful if such a comment included details such as:

  • Is this still relevant?
  • If so, what is blocking it?
  • Is it known what could be done to help move this forward?

Thank you for contributing!

(The cargo team is currently evaluating the use of Stale bot, and using #6035 as the tracking issue to gather feedback.)

If you're reading this comment from the distant future, fear not if this was closed automatically. If you believe it's still an issue please leave a comment and a team member can reopen this issue. Opening a new issue is also acceptable!

stale[bot] avatar Sep 18 '18 15:09 stale[bot]

This issue still exists.

The next step would be the implementation of a command (cargo download or cargo source, not sure which name makes more sense) which would download the .crate file for a crate, and optionally unpack it into a directory.

joshtriplett avatar Sep 18 '18 16:09 joshtriplett

cargo-download may cover this.

durka avatar Sep 18 '18 19:09 durka

I'm inclined to close this issue. Multiple implementations as third party tools exist, and we'd want an RFC to add a built-in command to cargo. I think there's no further progress that can be made in this repository without an RFC.

withoutboats avatar Sep 19 '18 17:09 withoutboats

That's fair; the next step is probably an RFC, not further implementation work.

joshtriplett avatar Sep 19 '18 17:09 joshtriplett

Another potentially similar command: https://github.com/nakabonne/rhack

epage avatar Aug 26 '22 20:08 epage

Yet another third-party implementation of this: cargo-dl. The major difference of this (and why I wrote it to replace my previous cargo download usage) is that it verifies the checksums to detect IO issues like cargo-download has. (It also has a couple user-friendly features like grabbing existing tarballs from cargo's cache if they exist, parallel downloading so you can quickly grab a range of versions cargo dl -e serde@=1.0.{0..9}, and not defaulting to dumping binary gzip data to stdout).

Nemo157 avatar Jan 27 '23 23:01 Nemo157

just want to mention two existing commands that fetch package sources: cargo fetch and cargo vendor.

adding a flag to cargo fetch that would allow fetching an individual package and print the directory of that package would be one possible solution.

lolbinarycat avatar May 17 '24 17:05 lolbinarycat