@@ -4,42 +4,9 @@ This document is about replacing the crate index. You can read about overriding
4
4
dependencies in the [ overriding dependencies] [ overriding ] section of this
5
5
documentation.
6
6
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:
43
10
44
11
* Vendoring - custom sources can be defined which represent crates on the local
45
12
filesystem. These sources are subsets of the source that they're replacing and
@@ -49,46 +16,64 @@ replacement Cargo can express:
49
16
cache for crates.io itself.
50
17
51
18
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.
56
22
57
23
As a consequence, source replacement is not appropriate for situations such as
58
24
patching a dependency or a private registry. Cargo supports patching
59
25
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 ] .
61
27
62
28
[ replace-section ] : reference/manifest.html#the-replace-section
63
29
[ overriding ] : reference/specifying-dependencies.html#overriding-dependencies
30
+ [ registries ] : reference/registries.html
64
31
65
32
### Configuration
66
33
67
34
Configuration of replacement sources is done through [ ` .cargo/config ` ] [ config ]
68
35
and the full set of available keys are:
69
36
70
37
``` 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
+
71
56
# Each source has its own table where the key is the name of the source
72
57
[source .the-source-name ]
73
58
74
59
# Indicate that `the-source-name` will be replaced with `another-source`,
75
60
# defined elsewhere
76
61
replace-with = " another-source"
77
62
78
- # Available kinds of sources that can be specified (described below)
63
+ # Several kinds of sources can be specified (described in more detail below):
79
64
registry = " https://example.com/path/to/index"
80
65
local-registry = " path/to/registry"
81
66
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:
86
67
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"
90
73
```
91
74
75
+ [ config ] : reference/config.html
76
+
92
77
### Registry Sources
93
78
94
79
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
107
92
made up of a set of ` *.crate ` files and an index like the normal registry is.
108
93
109
94
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 ` .
112
98
113
99
[ cargo-local-registry ] : https://crates.io/crates/cargo-local-registry
114
100
@@ -122,7 +108,8 @@ the crates that are present).
122
108
A "directory source" is similar to a local registry source where it contains a
123
109
number of crates available on the local filesystem, suitable for vendoring
124
110
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
126
113
installed with ` cargo install cargo-vendor ` .
127
114
128
115
[ cargo-vendor ] : https://crates.io/crates/cargo-vendor
0 commit comments