Skip to content

Commit ca62daf

Browse files
committed
Stabilize sparse-registry
1 parent 99ff79e commit ca62daf

File tree

8 files changed

+268
-302
lines changed

8 files changed

+268
-302
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),
@@ -750,6 +750,11 @@ const STABILIZED_TIMINGS: &str = "The -Ztimings option has been stabilized as --
750750

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

753+
const STABILISED_SPARSE_REGISTRY: &str = "This flag currently still sets the default protocol\
754+
to `sparse` when accessing crates.io. However, this will be removed in the future. \n\
755+
The stable equivalent is to set the config value `registries.crates-io.protocol = 'sparse'`\n\
756+
or environment variable `CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse`";
757+
753758
fn deserialize_build_std<'de, D>(deserializer: D) -> Result<Option<Vec<String>>, D::Error>
754759
where
755760
D: serde::Deserializer<'de>,
@@ -957,7 +962,10 @@ impl CliUnstable {
957962
"multitarget" => stabilized_warn(k, "1.64", STABILISED_MULTITARGET),
958963
"rustdoc-map" => self.rustdoc_map = parse_empty(k, v)?,
959964
"terminal-width" => self.terminal_width = Some(parse_usize_opt(v)?),
960-
"sparse-registry" => self.sparse_registry = parse_empty(k, v)?,
965+
"sparse-registry" => {
966+
stabilized_warn(k, "1.66", STABILISED_SPARSE_REGISTRY);
967+
self.sparse_registry = parse_empty(k, v)?;
968+
}
961969
"namespaced-features" => stabilized_warn(k, "1.60", STABILISED_NAMESPACED_FEATURES),
962970
"weak-dep-features" => stabilized_warn(k, "1.60", STABILIZED_WEAK_DEP_FEATURES),
963971
"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
* [publish-timeout](#publish-timeout) — Controls the timeout between uploading the crate and being available in the index
103102

104103
### allow-features
@@ -829,19 +828,6 @@ fn main() {
829828
}
830829
```
831830

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

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.

tests/testsuite/publish.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -2313,8 +2313,8 @@ fn wait_for_publish() {
23132313
)
23142314
.build();
23152315

2316-
p.cargo("publish --no-verify -Z sparse-registry -Z publish-timeout")
2317-
.masquerade_as_nightly_cargo(&["sparse-registry", "publish-timeout"])
2316+
p.cargo("publish --no-verify -Z publish-timeout")
2317+
.masquerade_as_nightly_cargo(&["publish-timeout"])
23182318
.replace_crates_io(registry.index_url())
23192319
.with_status(0)
23202320
.with_stderr(
@@ -2350,8 +2350,7 @@ See [..]
23502350
.file("src/main.rs", "fn main() {}")
23512351
.build();
23522352

2353-
p.cargo("build -Z sparse-registry")
2354-
.masquerade_as_nightly_cargo(&["sparse-registry"])
2353+
p.cargo("build")
23552354
.with_status(0)
23562355
.run();
23572356
}
@@ -2410,8 +2409,8 @@ fn wait_for_publish_underscore() {
24102409
)
24112410
.build();
24122411

2413-
p.cargo("publish --no-verify -Z sparse-registry -Z publish-timeout")
2414-
.masquerade_as_nightly_cargo(&["sparse-registry", "publish-timeout"])
2412+
p.cargo("publish --no-verify -Z publish-timeout")
2413+
.masquerade_as_nightly_cargo(&["publish-timeout"])
24152414
.replace_crates_io(registry.index_url())
24162415
.with_status(0)
24172416
.with_stderr(
@@ -2448,8 +2447,7 @@ See [..]
24482447
.file("src/main.rs", "fn main() {}")
24492448
.build();
24502449

2451-
p.cargo("build -Z sparse-registry")
2452-
.masquerade_as_nightly_cargo(&["sparse-registry"])
2450+
p.cargo("build")
24532451
.with_status(0)
24542452
.run();
24552453
}

0 commit comments

Comments
 (0)