Skip to content

Commit

Permalink
Stabilize sparse-registry
Browse files Browse the repository at this point in the history
  • Loading branch information
arlosi committed Nov 15, 2022
1 parent 16b0978 commit 9da9655
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 315 deletions.
14 changes: 12 additions & 2 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ unstable_cli_options!(
no_index_update: bool = ("Do not update the registry index even if the cache is outdated"),
panic_abort_tests: bool = ("Enable support to run tests with -Cpanic=abort"),
host_config: bool = ("Enable the [host] section in the .cargo/config.toml file"),
sparse_registry: bool = ("Support plain-HTTP-based crate registries"),
sparse_registry: bool = ("Use the sparse protocol when accessing crates.io"),
target_applies_to_host: bool = ("Enable the `target-applies-to-host` key in the .cargo/config.toml file"),
rustdoc_map: bool = ("Allow passing external documentation mappings to rustdoc"),
separate_nightlies: bool = (HIDDEN),
Expand Down Expand Up @@ -750,6 +750,11 @@ const STABILIZED_TIMINGS: &str = "The -Ztimings option has been stabilized as --

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

const STABILISED_SPARSE_REGISTRY: &str = "This flag currently still sets the default protocol\
to `sparse` when accessing crates.io. However, this will be removed in the future. \n\
The stable equivalent is to set the config value `registries.crates-io.protocol = 'sparse'`\n\
or environment variable `CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse`";

fn deserialize_build_std<'de, D>(deserializer: D) -> Result<Option<Vec<String>>, D::Error>
where
D: serde::Deserializer<'de>,
Expand Down Expand Up @@ -957,7 +962,12 @@ impl CliUnstable {
"multitarget" => stabilized_warn(k, "1.64", STABILISED_MULTITARGET),
"rustdoc-map" => self.rustdoc_map = parse_empty(k, v)?,
"terminal-width" => self.terminal_width = Some(parse_usize_opt(v)?),
"sparse-registry" => self.sparse_registry = parse_empty(k, v)?,
"sparse-registry" => {
// Once sparse-registry becomes the default for crates.io, `sparse_registry` should
// be removed entirely from `CliUnstable`.
stabilized_warn(k, "1.66", STABILISED_SPARSE_REGISTRY);
self.sparse_registry = parse_empty(k, v)?;
}
"namespaced-features" => stabilized_warn(k, "1.60", STABILISED_NAMESPACED_FEATURES),
"weak-dep-features" => stabilized_warn(k, "1.60", STABILIZED_WEAK_DEP_FEATURES),
"credential-process" => self.credential_process = parse_empty(k, v)?,
Expand Down
3 changes: 0 additions & 3 deletions src/cargo/sources/registry/http_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ impl<'cfg> HttpRegistry<'cfg> {
config: &'cfg Config,
name: &str,
) -> CargoResult<HttpRegistry<'cfg>> {
if !config.cli_unstable().sparse_registry {
anyhow::bail!("usage of sparse registries requires `-Z sparse-registry`");
}
let url = source_id.url().as_str();
// Ensure the url ends with a slash so we can concatenate paths.
if !url.ends_with('/') {
Expand Down
7 changes: 7 additions & 0 deletions src/doc/src/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,13 @@ commands like [`cargo publish`] that require authentication.

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

##### `registries.crates-io.protocol`
* Type: string
* Default: `git`
* Environment: `CARGO_REGISTRIES_CRATES_IO_PROTOCOL`

Specifies the protocol used to access crates.io. Allowed values are `git` or `sparse`.

#### `[registry]`

The `[registry]` table controls the default registry used when one is not
Expand Down
20 changes: 19 additions & 1 deletion src/doc/src/reference/registries.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ table has a key for each registry, for example:
my-registry = { index = "https://my-intranet:8080/git/index" }
```

The `index` key should be a URL to a git repository with the registry's index.
The `index` key should be a URL to a git repository with the registry's index or a
Cargo sparse registry URL with the `sparse+` prefix.

A crate can then depend on a crate from another registry by specifying the
`registry` key and a value of the registry's name in that dependency's entry
in `Cargo.toml`:
Expand All @@ -46,6 +48,21 @@ CARGO_REGISTRIES_MY_REGISTRY_INDEX=https://my-intranet:8080/git/index
> Note: [crates.io] does not accept packages that depend on crates from other
> registries.
### Sparse Registries
Cargo supports two remote registry protocols: `git` and `sparse`. The `git` protocol
stores index metadata in a git repository and requires Cargo to clone the entire repo.

The `sparse` protocol fetches individual metadata files using plain HTTP requests.
Since Cargo only downloads the metadata for relevant crates, the `sparse` protocol can
save significant time and bandwidth.

Cargo uses the `sparse` protocol for registry URLs that start with the `sparse+` prefix.

The format of a `sparse` index is identical to a checkout of a `git` index.

The protocol used for accessing crates.io can be set via the [`registries.crates-io.protocol`]
config key.

### Publishing to an Alternate Registry

If the registry supports web API access, then packages can be published
Expand Down Expand Up @@ -661,5 +678,6 @@ browser to log in and retrieve an API token.
[`cargo publish`]: ../commands/cargo-publish.md
[alphanumeric]: ../../std/primitive.char.html#method.is_alphanumeric
[config]: config.md
[`registries.crates-io.protocol`]: config.md#registriescrates-ioprotocol
[crates.io]: https://crates.io/
[publishing documentation]: publishing.md#cargo-owner
34 changes: 13 additions & 21 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ Each new feature described below should explain how to use it.
* Registries
* [credential-process](#credential-process) — Adds support for fetching registry tokens from an external authentication program.
* [`cargo logout`](#cargo-logout) — Adds the `logout` command to remove the currently saved registry token.
* [sparse-registry](#sparse-registry) — Adds support for fetching from static-file HTTP registries (`sparse+`)
* [publish-timeout](#publish-timeout) — Controls the timeout between uploading the crate and being available in the index

### allow-features
Expand Down Expand Up @@ -829,26 +828,6 @@ fn main() {
}
```

### sparse-registry
* Tracking Issue: [9069](https://github.com/rust-lang/cargo/issues/9069)
* RFC: [#2789](https://github.com/rust-lang/rfcs/pull/2789)

The `sparse-registry` feature allows cargo to interact with remote registries served
over plain HTTP rather than git. These registries can be identified by urls starting with
`sparse+http://` or `sparse+https://`.

When fetching index metadata over HTTP, Cargo only downloads the metadata for relevant
crates, which can save significant time and bandwidth.

The format of the sparse index is identical to a checkout of a git-based index.

The `registries.crates-io.protocol` config option can be used to set the default protocol
for crates.io. This option requires `-Z sparse-registry` to be enabled.

* `sparse` — Use sparse index.
* `git` — Use git index.
* If the option is unset, it will be sparse index if `-Z sparse-registry` is enabled, otherwise it will be git index.

### publish-timeout
* Tracking Issue: [11222](https://github.com/rust-lang/cargo/issues/11222)

Expand Down Expand Up @@ -1387,3 +1366,16 @@ See [workspace.package](workspaces.md#the-package-table),
[workspace.dependencies](workspaces.md#the-dependencies-table),
and [inheriting-a-dependency-from-a-workspace](specifying-dependencies.md#inheriting-a-dependency-from-a-workspace)
for more information.

### sparse-registry

Sparse registry support has been stabilized in the 1.66 release.

The `sparse-registry` feature allows cargo to interact with remote registries served
over plain HTTP rather than git. These registries can be identified by urls starting with
`sparse+http://` or `sparse+https://`.

When fetching index metadata over HTTP, Cargo only downloads the metadata for relevant
crates, which can save significant time and bandwidth.

The format of the sparse index is identical to a checkout of a git-based index.
4 changes: 1 addition & 3 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1314,9 +1314,7 @@ fn sparse_lockfile() {
.file("src/lib.rs", "")
.build();

p.cargo("-Zsparse-registry generate-lockfile")
.masquerade_as_nightly_cargo(&["sparse-registry"])
.run();
p.cargo("generate-lockfile").run();
assert_match_exact(
&p.read_lockfile(),
r#"# This file is automatically @generated by Cargo.
Expand Down
19 changes: 5 additions & 14 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2435,8 +2435,7 @@ fn wait_for_first_publish() {
.file("src/lib.rs", "")
.build();

p.cargo("publish --no-verify -Z sparse-registry")
.masquerade_as_nightly_cargo(&["sparse-registry"])
p.cargo("publish --no-verify")
.replace_crates_io(registry.index_url())
.with_status(0)
.with_stderr(
Expand Down Expand Up @@ -2473,10 +2472,7 @@ See [..]
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("build -Z sparse-registry")
.masquerade_as_nightly_cargo(&["sparse-registry"])
.with_status(0)
.run();
p.cargo("build").with_status(0).run();
}

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

p.cargo("publish --no-verify -Z sparse-registry")
.masquerade_as_nightly_cargo(&["sparse-registry"])
p.cargo("publish --no-verify")
.replace_crates_io(registry.index_url())
.with_status(0)
.with_stderr(
Expand Down Expand Up @@ -2559,10 +2554,7 @@ See [..]
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("build -Z sparse-registry")
.masquerade_as_nightly_cargo(&["sparse-registry"])
.with_status(0)
.run();
p.cargo("build").with_status(0).run();
}

#[cargo_test]
Expand Down Expand Up @@ -2613,8 +2605,7 @@ fn wait_for_subsequent_publish() {
.file("src/lib.rs", "")
.build();

p.cargo("publish --no-verify -Z sparse-registry")
.masquerade_as_nightly_cargo(&["sparse-registry"])
p.cargo("publish --no-verify")
.replace_crates_io(registry.index_url())
.with_status(0)
.with_stderr(
Expand Down
Loading

0 comments on commit 9da9655

Please sign in to comment.