Skip to content

Commit db40f1b

Browse files
committed
Auto merge of #6865 - fluffysquirrels:docs-sources, r=ehuss
Cargo book: source replacement Closes #6862
2 parents 85b4221 + 5526e10 commit db40f1b

File tree

2 files changed

+41
-52
lines changed

2 files changed

+41
-52
lines changed

src/doc/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignore built book
2+
book/

src/doc/src/reference/source-replacement.md

+39-52
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,9 @@ This document is about replacing the crate index. You can read about overriding
44
dependencies in the [overriding dependencies][overriding] section of this
55
documentation.
66

7-
Cargo supports the ability to **replace one source with another** to express
8-
strategies along the lines of mirrors or vendoring dependencies. Configuration
9-
is currently done through the [`.cargo/config` configuration][config] mechanism,
10-
like so:
11-
12-
[config]: reference/config.html
13-
14-
```toml
15-
# The `source` table is where all keys related to source-replacement
16-
# are stored.
17-
[source]
18-
19-
# Under the `source` table are a number of other tables whose keys are a
20-
# name for the relevant source. For example this section defines a new
21-
# source, called `my-awesome-source`, which comes from a directory
22-
# located at `vendor` relative to the directory containing this `.cargo/config`
23-
# file
24-
[source.my-awesome-source]
25-
directory = "vendor"
26-
27-
# Git sources can optionally specify a branch/tag/rev as well
28-
git = "https://example.com/path/to/repo"
29-
# branch = "master"
30-
# tag = "v1.0.1"
31-
# rev = "313f44e8"
32-
33-
# The crates.io default source for crates is available under the name
34-
# "crates-io", and here we use the `replace-with` key to indicate that it's
35-
# replaced with our source above.
36-
[source.crates-io]
37-
replace-with = "my-awesome-source"
38-
```
39-
40-
With this configuration Cargo attempts to look up all crates in the directory
41-
"vendor" rather than querying the online registry at crates.io. Using source
42-
replacement Cargo can express:
7+
A *source* is a provider that contains crates that may be included as
8+
dependencies for a package. Cargo supports the ability to **replace one source
9+
with another** to express strategies such as:
4310

4411
* Vendoring - custom sources can be defined which represent crates on the local
4512
filesystem. These sources are subsets of the source that they're replacing and
@@ -49,46 +16,64 @@ replacement Cargo can express:
4916
cache for crates.io itself.
5017

5118
Cargo has a core assumption about source replacement that the source code is
52-
exactly the same from both sources. In our above example Cargo assumes that all
53-
of the crates coming from `my-awesome-source` are the exact same as the copies
54-
from `crates-io`. Note that this also means that `my-awesome-source` is not
55-
allowed to have crates which are not present in the `crates-io` source.
19+
exactly the same from both sources. Note that this also means that
20+
a replacement source is not allowed to have crates which are not present in the
21+
original source.
5622

5723
As a consequence, source replacement is not appropriate for situations such as
5824
patching a dependency or a private registry. Cargo supports patching
5925
dependencies through the usage of [the `[replace]` key][replace-section], and
60-
private registry support is planned for a future version of Cargo.
26+
private registry support is described in [Registries][registries].
6127

6228
[replace-section]: reference/manifest.html#the-replace-section
6329
[overriding]: reference/specifying-dependencies.html#overriding-dependencies
30+
[registries]: reference/registries.html
6431

6532
### Configuration
6633

6734
Configuration of replacement sources is done through [`.cargo/config`][config]
6835
and the full set of available keys are:
6936

7037
```toml
38+
# The `source` table is where all keys related to source-replacement
39+
# are stored.
40+
[source]
41+
42+
# Under the `source` table are a number of other tables whose keys are a
43+
# name for the relevant source. For example this section defines a new
44+
# source, called `my-vendor-source`, which comes from a directory
45+
# located at `vendor` relative to the directory containing this `.cargo/config`
46+
# file
47+
[source.my-vendor-source]
48+
directory = "vendor"
49+
50+
# The crates.io default source for crates is available under the name
51+
# "crates-io", and here we use the `replace-with` key to indicate that it's
52+
# replaced with our source above.
53+
[source.crates-io]
54+
replace-with = "my-vendor-source"
55+
7156
# Each source has its own table where the key is the name of the source
7257
[source.the-source-name]
7358

7459
# Indicate that `the-source-name` will be replaced with `another-source`,
7560
# defined elsewhere
7661
replace-with = "another-source"
7762

78-
# Available kinds of sources that can be specified (described below)
63+
# Several kinds of sources can be specified (described in more detail below):
7964
registry = "https://example.com/path/to/index"
8065
local-registry = "path/to/registry"
8166
directory = "path/to/vendor"
82-
```
83-
84-
The `crates-io` represents the crates.io online registry (default source of
85-
crates) and can be replaced with:
8667

87-
```toml
88-
[source.crates-io]
89-
replace-with = 'another-source'
68+
# Git sources can optionally specify a branch/tag/rev as well
69+
git = "https://example.com/path/to/repo"
70+
# branch = "master"
71+
# tag = "v1.0.1"
72+
# rev = "313f44e8"
9073
```
9174

75+
[config]: reference/config.html
76+
9277
### Registry Sources
9378

9479
A "registry source" is one that is the same as crates.io itself. That is, it has
@@ -107,8 +92,9 @@ are downloaded ahead of time, typically sync'd with a `Cargo.lock`, and are
10792
made up of a set of `*.crate` files and an index like the normal registry is.
10893

10994
The primary way to manage and create local registry sources is through the
110-
[`cargo-local-registry`][cargo-local-registry] subcommand, available on
111-
crates.io and can be installed with `cargo install cargo-local-registry`.
95+
[`cargo-local-registry`][cargo-local-registry] subcommand,
96+
[available on crates.io][cargo-local-registry] and can be installed with
97+
`cargo install cargo-local-registry`.
11298

11399
[cargo-local-registry]: https://crates.io/crates/cargo-local-registry
114100

@@ -122,7 +108,8 @@ the crates that are present).
122108
A "directory source" is similar to a local registry source where it contains a
123109
number of crates available on the local filesystem, suitable for vendoring
124110
dependencies. Also like local registries, directory sources can primarily be
125-
managed by an external subcommand, [`cargo-vendor`][cargo-vendor], which can be
111+
managed by an external subcommand, [`cargo-vendor`][cargo-vendor],
112+
[available on crates.io][cargo-vendor] and can be
126113
installed with `cargo install cargo-vendor`.
127114

128115
[cargo-vendor]: https://crates.io/crates/cargo-vendor

0 commit comments

Comments
 (0)