0

As in I copy the /path/to/home/.cargo/registry directory (or the /path/to/home/.cargo/registry/src directory specifically), from my system and replace the one in a different system with this copy and the same set of crates are available now in that system (by "available" I mean that I can include those crates in a project as dependencies and build it with cargo build --offline or vendor them into my project with cargo vendor --offline, after adding them to Cargo.toml).

Keyboard Penman
  • 162
  • 1
  • 11

1 Answers1

3

I never tried it but in theory, copying the contents of ~/.cargo/registry from one system to another should work. ~/.cargo/registry is a source cache rather than a build cache containing compiled artefacts which may not be transferable depending on the two systems you have. It contains the source code of your dependencies, both packed (~/.cargo/registry/cache) and unpacked (~/.cargo/registry/src). If you copy something, copy the packed versions (the .crate files located in ~/.cargo/registry/cache), as Cargo uses them to lookup dependencies and unpacks them for you, once they are required by one of your projects. Read more about the ~/.cargo directory (called "Cargo Home") in the Cargo Book.

Instead of working with the source cache directly though, you should prefer cargo vendor, as it is the command specifically designed for such use-cases.

Jonas Fassbender
  • 2,371
  • 1
  • 3
  • 19