Skip to content

Commit

Permalink
Stabilize sparse-registry
Browse files Browse the repository at this point in the history
  • Loading branch information
arlosi committed Oct 13, 2022
1 parent b592ba4 commit 1608199
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 294 deletions.
12 changes: 10 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,10 @@ 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" => {
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 @@ -891,6 +891,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 @@ -45,6 +47,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 @@ -660,5 +677,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
14 changes: 0 additions & 14 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,19 +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.

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

Expand Down
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
Loading

0 comments on commit 1608199

Please sign in to comment.