-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
This is an open-ended issue about ultimately determining the UX for how users opt-in to sparse registries, and how that interacts with URLs, Package IDs, Cargo.lock files, config files, etc.
The approach may differ from crates.io compared to third-party registries. However, I think it would be good to think about them together so that there is a coherent story.
- It is assumed the git index and the sparse index cannot be served from the same URL.
- The URL is stored in
Cargo.lock
files andCargo.toml
in.crate
files for alt-registries. What is the migration story for alt-registries that want to support sparse registries? What if they want to offer both git and sparse at the same time? - Cargo should give users the ability to choose whether to use sparse or git index.
- Users may be able to opt-in to a specific registry protocol using source-replacement in the short term, but it would be nice if there was something simpler.
- Auto-detection is desired, but Cargo will need to know about both URLs. However, auto-detection may be very difficult to implement well.
Some roughly thought-out proposals:
Proposal 1 — Alt-registry config
Add a new registry.*.sparse
key which is the URL for a sparse index. Allow both index
and sparse
to be specified at the same time. Cargo will use the index
URL in Cargo.lock
and will generally treat the two URLs as interchangeable.
[registry.my-registry]
index = "https://example.com/crates/index.git"
sparse = "https://example.com/crates/sparse/"
If only sparse
is listed, then Cargo will only use the sparse index, and the sparse URL will be used in Cargo.lock
and PackageIDs and published Cargo.toml
files (alt-registries).
Proposal 2 — Easy toggle
Add a "preferred" setting which indicates the preferred mechanism for speaking to a registry. It might look something like this:
[registries.crates-io]
preferred = "sparse"
Via environment variables, this would look like CARGO_REGISTRIES_CRATES_IO_PREFERRED=sparse
.
(Bikeshed name welcome.)
This setting can be used for crates.io or any other registry.
Proposal 3 — Source replacement
This option works today (AFAIK), but is a little clumsy.
[registries.foo]
index = "https://example.com/crates/index.git"
[source.foo]
replace-with = "foo-sparse"
[source.foo-sparse]
index = "sparse+https://example.com/crates/sparse/"
Proposal 4 — Migration story
An organization using an alt registry may want to transition to using sparse indexes. There are a few options:
- They could serve both git and sparse, and have all users update their config as suggested in Proposal 1 above. They could keep both indexes alive (similar to how crates.io will work).
- They could temporarily serve both. At some point, they will switch to sparse-only after all users have updated their configs as suggested in Proposal 1. However, they will need to keep the config with the old git URL to handle
Cargo.lock
and.crate
files. - They could do a hard-switch. They could drop their git server, and change everyone's config to only know about sparse (as suggested in Proposal 5), and update all
Cargo.lock
files to use the new URL, and rebuild all.crate
files to the new URL. (This sounds almost too painful to suggest.)
Proposal 5 — New registries
New registries may want to only support sparse indexes. In that case, they should have a simple config:
[registries.foo]
sparse = "https://exmaple.com/crates/index/"
or a different idea would be:
[registries.foo]
index = "sparse+https://example.com/crates/index/"
All URLs in Cargo.lock
and other places will use the sparse URL.