rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.58k stars 2.39k forks source link

Feature Request: A way to backup/restore cargo install'd crates #7322

Open kevinmost opened 5 years ago

kevinmost commented 5 years ago

Describe the problem you are trying to solve I use cargo to install some system utilities on my machine. I generally like to back up the installed packages + flags I used to install them to a file that I can use to restore those packages onto new machines. For example, on OS X, brew-bundle supports this, letting you run brew bundle dump to output a file that can be read via brew bundle later to restore this set of installed packages.

Cargo tracks installed crates via the ~/.cargo/.crates.toml file. This seems to be the same file that is read when you run cargo install --list.

Describe the solution you'd like I'd like to see a cargo install --dump or similar that would output the list of installed crates to stdout, but rather than in a human-readable format, in a json/toml/other structured format.

The companion command would be something like cargo install --dump /path/to/dumpfile.toml, which would cargo install all listed crates with all of their options.

Notes If this is a desirable feature, I'd be happy to submit a PR adding this functionality.

Thanks in advance for any thoughts!

jhessin commented 5 years ago

I would definitely be interested in this.

dsully commented 2 years ago

+1 on this idea.

weihanglo commented 1 year ago

We could probably reuse .crates2.json file. InstallInfo struct should contain sufficient information for us to reinstall. (Maybe source replacement and patch are not included but that should be fine I guess?).

Some things need to figure out

Otherwise the implementation should be straightforward I guess, though I didn't dive deep much.