orcy
orcy

Reputation: 1372

Cargo registry directory

How do I specify another directory where cargo keeps the unpacked sources, e.g. on Windows this is %userprofile%/.cargo/registry/src?

I working that is going to be a collection of crates like:

myproject-tree/
  foo
    +Cargo.toml
  bar
    +Cargo.toml

So I would like the dependencies to be loaded in unpacked somewhere near the myproject-tree directory, e.g.

myproject-tree/
cargo-cache/

I think that would make it easier to inspect the code of dependencies (e.g. in the code editors with file tree UI). I can see that there is CARGO_HOME that seems like it has something like this, but it does not look convenient, e.g. each time I am going to work with myproject-tree I have to set it.

Upvotes: 1

Views: 2893

Answers (1)

orcy
orcy

Reputation: 1372

Looks like this is possible. I think it called "vendoring" and repositories like Fuchsia and Mozilla has source copy of third-party crates in their repositories. This is what I have found:

  • Cargo supports "Source replacement" thing configured in .cargo/config, which can be in a project relative dir:

With this configuration Cargo attempts to look up all crates in the directory "vendor" rather than querying the online registry at crates.io. Using source replacement Cargo can express:

Vendoring - custom sources can be defined which represent crates on the local filesystem. These sources are subsets of the source that they're replacing and can be checked into packages if necessary.

Mirroring - sources can be replaced with an equivalent version which acts as a cache for crates.io itself.

Simply run cargo vendor inside of any Cargo project:

Upvotes: 1

Related Questions