Skip to content

Commit d99151a

Browse files
committed
Stabilize sparse-registry
1 parent 0b61503 commit d99151a

File tree

7 files changed

+262
-294
lines changed

7 files changed

+262
-294
lines changed

src/cargo/core/features.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ unstable_cli_options!(
681681
no_index_update: bool = ("Do not update the registry index even if the cache is outdated"),
682682
panic_abort_tests: bool = ("Enable support to run tests with -Cpanic=abort"),
683683
host_config: bool = ("Enable the [host] section in the .cargo/config.toml file"),
684-
sparse_registry: bool = ("Support plain-HTTP-based crate registries"),
684+
sparse_registry: bool = ("Use the sparse protocol when accessing crates.io"),
685685
target_applies_to_host: bool = ("Enable the `target-applies-to-host` key in the .cargo/config.toml file"),
686686
rustdoc_map: bool = ("Allow passing external documentation mappings to rustdoc"),
687687
separate_nightlies: bool = (HIDDEN),
@@ -749,6 +749,11 @@ const STABILIZED_TIMINGS: &str = "The -Ztimings option has been stabilized as --
749749

750750
const STABILISED_MULTITARGET: &str = "Multiple `--target` options are now always available.";
751751

752+
const STABILISED_SPARSE_REGISTRY: &str = "This flag currently still sets the default protocol\
753+
to `sparse` when accessing crates.io. However, this will be removed in the future. \n\
754+
The stable equivalent is to set the config value `registries.crates-io.protocol = 'sparse'`\n\
755+
or environment variable `CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse`";
756+
752757
fn deserialize_build_std<'de, D>(deserializer: D) -> Result<Option<Vec<String>>, D::Error>
753758
where
754759
D: serde::Deserializer<'de>,
@@ -955,7 +960,10 @@ impl CliUnstable {
955960
"multitarget" => stabilized_warn(k, "1.64", STABILISED_MULTITARGET),
956961
"rustdoc-map" => self.rustdoc_map = parse_empty(k, v)?,
957962
"terminal-width" => self.terminal_width = Some(parse_usize_opt(v)?),
958-
"sparse-registry" => self.sparse_registry = parse_empty(k, v)?,
963+
"sparse-registry" => {
964+
stabilized_warn(k, "1.66", STABILISED_SPARSE_REGISTRY);
965+
self.sparse_registry = parse_empty(k, v)?;
966+
}
959967
"namespaced-features" => stabilized_warn(k, "1.60", STABILISED_NAMESPACED_FEATURES),
960968
"weak-dep-features" => stabilized_warn(k, "1.60", STABILIZED_WEAK_DEP_FEATURES),
961969
"credential-process" => self.credential_process = parse_empty(k, v)?,

src/cargo/sources/registry/http_remote.rs

-3
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ impl<'cfg> HttpRegistry<'cfg> {
131131
config: &'cfg Config,
132132
name: &str,
133133
) -> CargoResult<HttpRegistry<'cfg>> {
134-
if !config.cli_unstable().sparse_registry {
135-
anyhow::bail!("usage of sparse registries requires `-Z sparse-registry`");
136-
}
137134
let url = source_id.url().as_str();
138135
// Ensure the url ends with a slash so we can concatenate paths.
139136
if !url.ends_with('/') {

src/doc/src/reference/config.md

+7
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,13 @@ commands like [`cargo publish`] that require authentication.
891891

892892
Can be overridden with the `--token` command-line option.
893893

894+
##### `registries.crates-io.protocol`
895+
* Type: string
896+
* Default: `git`
897+
* Environment: `CARGO_REGISTRIES_CRATES_IO_PROTOCOL`
898+
899+
Specifies the protocol used to access crates.io. Allowed values are `git` or `sparse`.
900+
894901
#### `[registry]`
895902

896903
The `[registry]` table controls the default registry used when one is not

src/doc/src/reference/registries.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ table has a key for each registry, for example:
1919
my-registry = { index = "https://my-intranet:8080/git/index" }
2020
```
2121

22-
The `index` key should be a URL to a git repository with the registry's index.
22+
The `index` key should be a URL to a git repository with the registry's index or a
23+
Cargo sparse registry URL with the `sparse+` prefix.
24+
2325
A crate can then depend on a crate from another registry by specifying the
2426
`registry` key and a value of the registry's name in that dependency's entry
2527
in `Cargo.toml`:
@@ -45,6 +47,21 @@ CARGO_REGISTRIES_MY_REGISTRY_INDEX=https://my-intranet:8080/git/index
4547
> Note: [crates.io] does not accept packages that depend on crates from other
4648
> registries.
4749
50+
### Sparse Registries
51+
Cargo supports two remote registry protocols: `git` and `sparse`. The `git` protocol
52+
stores index metadata in a git repository and requires Cargo to clone the entire repo.
53+
54+
The `sparse` protocol fetches individual metadata files using plain HTTP requests.
55+
Since Cargo only downloads the metadata for relevant crates, the `sparse` protocol can
56+
save significant time and bandwidth.
57+
58+
Cargo uses the `sparse` protocol for registry URLs that start with the `sparse+` prefix.
59+
60+
The format of a `sparse` index is identical to a checkout of a `git` index.
61+
62+
The protocol used for accessing crates.io can be set via the [`registries.crates-io.protocol`]
63+
config key.
64+
4865
### Publishing to an Alternate Registry
4966

5067
If the registry supports web API access, then packages can be published
@@ -660,5 +677,6 @@ browser to log in and retrieve an API token.
660677
[`cargo publish`]: ../commands/cargo-publish.md
661678
[alphanumeric]: ../../std/primitive.char.html#method.is_alphanumeric
662679
[config]: config.md
680+
[`registries.crates-io.protocol`]: config.md#registriescrates-ioprotocol
663681
[crates.io]: https://crates.io/
664682
[publishing documentation]: publishing.md#cargo-owner

src/doc/src/reference/unstable.md

-14
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ Each new feature described below should explain how to use it.
9898
* Registries
9999
* [credential-process](#credential-process) — Adds support for fetching registry tokens from an external authentication program.
100100
* [`cargo logout`](#cargo-logout) — Adds the `logout` command to remove the currently saved registry token.
101-
* [sparse-registry](#sparse-registry) — Adds support for fetching from static-file HTTP registries (`sparse+`)
102101

103102
### allow-features
104103

@@ -828,19 +827,6 @@ fn main() {
828827
}
829828
```
830829

831-
### sparse-registry
832-
* Tracking Issue: [9069](https://github.com/rust-lang/cargo/issues/9069)
833-
* RFC: [#2789](https://github.com/rust-lang/rfcs/pull/2789)
834-
835-
The `sparse-registry` feature allows cargo to interact with remote registries served
836-
over plain HTTP rather than git. These registries can be identified by urls starting with
837-
`sparse+http://` or `sparse+https://`.
838-
839-
When fetching index metadata over HTTP, Cargo only downloads the metadata for relevant
840-
crates, which can save significant time and bandwidth.
841-
842-
The format of the sparse index is identical to a checkout of a git-based index.
843-
844830
### credential-process
845831
* Tracking Issue: [#8933](https://github.com/rust-lang/cargo/issues/8933)
846832
* RFC: [#2730](https://github.com/rust-lang/rfcs/pull/2730)

tests/testsuite/alt_registry.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1314,9 +1314,7 @@ fn sparse_lockfile() {
13141314
.file("src/lib.rs", "")
13151315
.build();
13161316

1317-
p.cargo("-Zsparse-registry generate-lockfile")
1318-
.masquerade_as_nightly_cargo(&["sparse-registry"])
1319-
.run();
1317+
p.cargo("generate-lockfile").run();
13201318
assert_match_exact(
13211319
&p.read_lockfile(),
13221320
r#"# This file is automatically @generated by Cargo.

0 commit comments

Comments
 (0)