rust-lang / cargo

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

Support for (or documentation for) multiple "directory" type registries #10045

Open gspr opened 3 years ago

gspr commented 3 years ago

Problem

I often find it desireable to replace source.crates-io with a local registry. Thanks to source replacement, that's as easy as:

[net]
offline = true

[source]

[source.crates-io]
replace-with = "local-replacement"

[source.local-replacement]
directory = "/a/local/directory"

Here, /a/local/directory is simply a directory containing directories of the form cratename-version, each one of those containing the source code for a crate at a fixed version. Cargo will then not reach out to crates.io to find dependencies, but rather look only in that directory.

It seems unclear from the documentation whether one can add more such directories for other dependencies, and have those checked whenever a dependency cannot be satisfied by the one in source.local-replacement. One way seems to be to set up a full-blown secondary registry locally, which feels like a massive overkill for a reasonably simple task other programming language tooling can do. And it seems like Cargo must already have the functionality to treat a simple filesystem directory as a registry (for the purposes of source replacement at least).

Proposed Solution

It would be extremely convenient to be able to specify another stanza like

[source.more-crates]
directory = "/another/local/directory"

and have Cargo look there for dependencies that it cannot satisfy from source.local-replacement.

Notes

It is unclear to me whether this is a problem of Cargo's capabilities (in which case this is a feature request), Cargo's documentation (in which case this a documentation bug report) or me (in which case this is a cry for hel… I mean support request).

Eh2406 commented 3 years ago

More discussion is at https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/clarifying.20sources

gspr commented 3 years ago

In case others need this, one can work around the problem quite easily using UnionFS/OverlayFS. Details here: https://stackoverflow.com/a/69977327

Short version: Create a new source with directory = "/the/union", and use it as your source.crates-io replacement. Then use UnionFS/OverlayFS to make /the/union a union of /a/local/directory and /another/local/directory (with whatever priority order you prefer).