Skip to content

Commit 9da9655

Browse files
committed
Stabilize sparse-registry
1 parent 16b0978 commit 9da9655

File tree

8 files changed

+282
-315
lines changed

8 files changed

+282
-315
lines changed

src/cargo/core/features.rs

Lines changed: 12 additions & 2 deletions
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,12 @@ 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+
// Once sparse-registry becomes the default for crates.io, `sparse_registry` should
967+
// be removed entirely from `CliUnstable`.
968+
stabilized_warn(k, "1.66", STABILISED_SPARSE_REGISTRY);
969+
self.sparse_registry = parse_empty(k, v)?;
970+
}
961971
"namespaced-features" => stabilized_warn(k, "1.60", STABILISED_NAMESPACED_FEATURES),
962972
"weak-dep-features" => stabilized_warn(k, "1.60", STABILIZED_WEAK_DEP_FEATURES),
963973
"credential-process" => self.credential_process = parse_empty(k, v)?,

src/cargo/sources/registry/http_remote.rs

Lines changed: 0 additions & 3 deletions
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,13 @@ commands like [`cargo publish`] that require authentication.
892892

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

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

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

src/doc/src/reference/registries.md

Lines changed: 19 additions & 1 deletion
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`:
@@ -46,6 +48,21 @@ CARGO_REGISTRIES_MY_REGISTRY_INDEX=https://my-intranet:8080/git/index
4648
> Note: [crates.io] does not accept packages that depend on crates from other
4749
> registries.
4850
51+
### Sparse Registries
52+
Cargo supports two remote registry protocols: `git` and `sparse`. The `git` protocol
53+
stores index metadata in a git repository and requires Cargo to clone the entire repo.
54+
55+
The `sparse` protocol fetches individual metadata files using plain HTTP requests.
56+
Since Cargo only downloads the metadata for relevant crates, the `sparse` protocol can
57+
save significant time and bandwidth.
58+
59+
Cargo uses the `sparse` protocol for registry URLs that start with the `sparse+` prefix.
60+
61+
The format of a `sparse` index is identical to a checkout of a `git` index.
62+
63+
The protocol used for accessing crates.io can be set via the [`registries.crates-io.protocol`]
64+
config key.
65+
4966
### Publishing to an Alternate Registry
5067

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

src/doc/src/reference/unstable.md

Lines changed: 13 additions & 21 deletions
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,26 +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-
845-
The `registries.crates-io.protocol` config option can be used to set the default protocol
846-
for crates.io. This option requires `-Z sparse-registry` to be enabled.
847-
848-
* `sparse` — Use sparse index.
849-
* `git` — Use git index.
850-
* If the option is unset, it will be sparse index if `-Z sparse-registry` is enabled, otherwise it will be git index.
851-
852831
### publish-timeout
853832
* Tracking Issue: [11222](https://github.com/rust-lang/cargo/issues/11222)
854833

@@ -1387,3 +1366,16 @@ See [workspace.package](workspaces.md#the-package-table),
13871366
[workspace.dependencies](workspaces.md#the-dependencies-table),
13881367
and [inheriting-a-dependency-from-a-workspace](specifying-dependencies.md#inheriting-a-dependency-from-a-workspace)
13891368
for more information.
1369+
1370+
### sparse-registry
1371+
1372+
Sparse registry support has been stabilized in the 1.66 release.
1373+
1374+
The `sparse-registry` feature allows cargo to interact with remote registries served
1375+
over plain HTTP rather than git. These registries can be identified by urls starting with
1376+
`sparse+http://` or `sparse+https://`.
1377+
1378+
When fetching index metadata over HTTP, Cargo only downloads the metadata for relevant
1379+
crates, which can save significant time and bandwidth.
1380+
1381+
The format of the sparse index is identical to a checkout of a git-based index.

tests/testsuite/alt_registry.rs

Lines changed: 1 addition & 3 deletions
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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,8 +2435,7 @@ fn wait_for_first_publish() {
24352435
.file("src/lib.rs", "")
24362436
.build();
24372437

2438-
p.cargo("publish --no-verify -Z sparse-registry")
2439-
.masquerade_as_nightly_cargo(&["sparse-registry"])
2438+
p.cargo("publish --no-verify")
24402439
.replace_crates_io(registry.index_url())
24412440
.with_status(0)
24422441
.with_stderr(
@@ -2473,10 +2472,7 @@ See [..]
24732472
.file("src/main.rs", "fn main() {}")
24742473
.build();
24752474

2476-
p.cargo("build -Z sparse-registry")
2477-
.masquerade_as_nightly_cargo(&["sparse-registry"])
2478-
.with_status(0)
2479-
.run();
2475+
p.cargo("build").with_status(0).run();
24802476
}
24812477

24822478
/// A separate test is needed for package names with - or _ as they hit
@@ -2520,8 +2516,7 @@ fn wait_for_first_publish_underscore() {
25202516
.file("src/lib.rs", "")
25212517
.build();
25222518

2523-
p.cargo("publish --no-verify -Z sparse-registry")
2524-
.masquerade_as_nightly_cargo(&["sparse-registry"])
2519+
p.cargo("publish --no-verify")
25252520
.replace_crates_io(registry.index_url())
25262521
.with_status(0)
25272522
.with_stderr(
@@ -2559,10 +2554,7 @@ See [..]
25592554
.file("src/main.rs", "fn main() {}")
25602555
.build();
25612556

2562-
p.cargo("build -Z sparse-registry")
2563-
.masquerade_as_nightly_cargo(&["sparse-registry"])
2564-
.with_status(0)
2565-
.run();
2557+
p.cargo("build").with_status(0).run();
25662558
}
25672559

25682560
#[cargo_test]
@@ -2613,8 +2605,7 @@ fn wait_for_subsequent_publish() {
26132605
.file("src/lib.rs", "")
26142606
.build();
26152607

2616-
p.cargo("publish --no-verify -Z sparse-registry")
2617-
.masquerade_as_nightly_cargo(&["sparse-registry"])
2608+
p.cargo("publish --no-verify")
26182609
.replace_crates_io(registry.index_url())
26192610
.with_status(0)
26202611
.with_stderr(

0 commit comments

Comments
 (0)