]> git.proxmox.com Git - cargo.git/blob - src/doc/src/commands/cargo-fetch.md
93e8aba3f260c1bc9dedbd287971f4df0f40268b
[cargo.git] / src / doc / src / commands / cargo-fetch.md
1 # cargo-fetch(1)
2
3
4
5
6 ## NAME
7
8 cargo-fetch - Fetch dependencies of a package from the network
9
10 ## SYNOPSIS
11
12 `cargo fetch` [_options_]
13
14 ## DESCRIPTION
15
16 If a `Cargo.lock` file is available, this command will ensure that all of the
17 git dependencies and/or registry dependencies are downloaded and locally
18 available. Subsequent Cargo commands will be able to run offline after a `cargo
19 fetch` unless the lock file changes.
20
21 If the lock file is not available, then this command will generate the lock
22 file before fetching the dependencies.
23
24 If `--target` is not specified, then all target dependencies are fetched.
25
26 See also the [cargo-prefetch](https://crates.io/crates/cargo-prefetch)
27 plugin which adds a command to download popular crates. This may be useful if
28 you plan to use Cargo without a network with the `--offline` flag.
29
30 ## OPTIONS
31
32 ### Fetch options
33
34 <dl>
35 <dt class="option-term" id="option-cargo-fetch---target"><a class="option-anchor" href="#option-cargo-fetch---target"></a><code>--target</code> <em>triple</em></dt>
36 <dd class="option-desc">Fetch for the given architecture. The default is all architectures. The general format of the triple is
37 <code>&lt;arch&gt;&lt;sub&gt;-&lt;vendor&gt;-&lt;sys&gt;-&lt;abi&gt;</code>. Run <code>rustc --print target-list</code> for a
38 list of supported targets. This flag may be specified multiple times.</p>
39 <p>This may also be specified with the <code>build.target</code>
40 <a href="../reference/config.html">config value</a>.</p>
41 <p>Note that specifying this flag makes Cargo run in a different mode where the
42 target artifacts are placed in a separate directory. See the
43 <a href="../guide/build-cache.html">build cache</a> documentation for more details.</dd>
44
45
46 </dl>
47
48 ### Display Options
49
50 <dl>
51 <dt class="option-term" id="option-cargo-fetch--v"><a class="option-anchor" href="#option-cargo-fetch--v"></a><code>-v</code></dt>
52 <dt class="option-term" id="option-cargo-fetch---verbose"><a class="option-anchor" href="#option-cargo-fetch---verbose"></a><code>--verbose</code></dt>
53 <dd class="option-desc">Use verbose output. May be specified twice for &quot;very verbose&quot; output which
54 includes extra output such as dependency warnings and build script output.
55 May also be specified with the <code>term.verbose</code>
56 <a href="../reference/config.html">config value</a>.</dd>
57
58
59 <dt class="option-term" id="option-cargo-fetch--q"><a class="option-anchor" href="#option-cargo-fetch--q"></a><code>-q</code></dt>
60 <dt class="option-term" id="option-cargo-fetch---quiet"><a class="option-anchor" href="#option-cargo-fetch---quiet"></a><code>--quiet</code></dt>
61 <dd class="option-desc">Do not print cargo log messages.
62 May also be specified with the <code>term.quiet</code>
63 <a href="../reference/config.html">config value</a>.</dd>
64
65
66 <dt class="option-term" id="option-cargo-fetch---color"><a class="option-anchor" href="#option-cargo-fetch---color"></a><code>--color</code> <em>when</em></dt>
67 <dd class="option-desc">Control when colored output is used. Valid values:</p>
68 <ul>
69 <li><code>auto</code> (default): Automatically detect if color support is available on the
70 terminal.</li>
71 <li><code>always</code>: Always display colors.</li>
72 <li><code>never</code>: Never display colors.</li>
73 </ul>
74 <p>May also be specified with the <code>term.color</code>
75 <a href="../reference/config.html">config value</a>.</dd>
76
77
78 </dl>
79
80 ### Manifest Options
81
82 <dl>
83 <dt class="option-term" id="option-cargo-fetch---manifest-path"><a class="option-anchor" href="#option-cargo-fetch---manifest-path"></a><code>--manifest-path</code> <em>path</em></dt>
84 <dd class="option-desc">Path to the <code>Cargo.toml</code> file. By default, Cargo searches for the
85 <code>Cargo.toml</code> file in the current directory or any parent directory.</dd>
86
87
88
89 <dt class="option-term" id="option-cargo-fetch---frozen"><a class="option-anchor" href="#option-cargo-fetch---frozen"></a><code>--frozen</code></dt>
90 <dt class="option-term" id="option-cargo-fetch---locked"><a class="option-anchor" href="#option-cargo-fetch---locked"></a><code>--locked</code></dt>
91 <dd class="option-desc">Either of these flags requires that the <code>Cargo.lock</code> file is
92 up-to-date. If the lock file is missing, or it needs to be updated, Cargo will
93 exit with an error. The <code>--frozen</code> flag also prevents Cargo from
94 attempting to access the network to determine if it is out-of-date.</p>
95 <p>These may be used in environments where you want to assert that the
96 <code>Cargo.lock</code> file is up-to-date (such as a CI build) or want to avoid network
97 access.</dd>
98
99
100 <dt class="option-term" id="option-cargo-fetch---offline"><a class="option-anchor" href="#option-cargo-fetch---offline"></a><code>--offline</code></dt>
101 <dd class="option-desc">Prevents Cargo from accessing the network for any reason. Without this
102 flag, Cargo will stop with an error if it needs to access the network and
103 the network is not available. With this flag, Cargo will attempt to
104 proceed without the network if possible.</p>
105 <p>Beware that this may result in different dependency resolution than online
106 mode. Cargo will restrict itself to crates that are downloaded locally, even
107 if there might be a newer version as indicated in the local copy of the index.
108 See the <a href="cargo-fetch.html">cargo-fetch(1)</a> command to download dependencies before going
109 offline.</p>
110 <p>May also be specified with the <code>net.offline</code> <a href="../reference/config.html">config value</a>.</dd>
111
112
113 </dl>
114
115 ### Common Options
116
117 <dl>
118
119 <dt class="option-term" id="option-cargo-fetch-+toolchain"><a class="option-anchor" href="#option-cargo-fetch-+toolchain"></a><code>+</code><em>toolchain</em></dt>
120 <dd class="option-desc">If Cargo has been installed with rustup, and the first argument to <code>cargo</code>
121 begins with <code>+</code>, it will be interpreted as a rustup toolchain name (such
122 as <code>+stable</code> or <code>+nightly</code>).
123 See the <a href="https://rust-lang.github.io/rustup/overrides.html">rustup documentation</a>
124 for more information about how toolchain overrides work.</dd>
125
126
127 <dt class="option-term" id="option-cargo-fetch---config"><a class="option-anchor" href="#option-cargo-fetch---config"></a><code>--config</code> <em>KEY=VALUE</em> or <em>PATH</em></dt>
128 <dd class="option-desc">Overrides a Cargo configuration value. The argument should be in TOML syntax of <code>KEY=VALUE</code>,
129 or provided as a path to an extra configuration file. This flag may be specified multiple times.
130 See the <a href="../reference/config.html#command-line-overrides">command-line overrides section</a> for more information.</dd>
131
132
133 <dt class="option-term" id="option-cargo-fetch--h"><a class="option-anchor" href="#option-cargo-fetch--h"></a><code>-h</code></dt>
134 <dt class="option-term" id="option-cargo-fetch---help"><a class="option-anchor" href="#option-cargo-fetch---help"></a><code>--help</code></dt>
135 <dd class="option-desc">Prints help information.</dd>
136
137
138 <dt class="option-term" id="option-cargo-fetch--Z"><a class="option-anchor" href="#option-cargo-fetch--Z"></a><code>-Z</code> <em>flag</em></dt>
139 <dd class="option-desc">Unstable (nightly-only) flags to Cargo. Run <code>cargo -Z help</code> for details.</dd>
140
141
142 </dl>
143
144
145 ## ENVIRONMENT
146
147 See [the reference](../reference/environment-variables.html) for
148 details on environment variables that Cargo reads.
149
150
151 ## EXIT STATUS
152
153 * `0`: Cargo succeeded.
154 * `101`: Cargo failed to complete.
155
156
157 ## EXAMPLES
158
159 1. Fetch all dependencies:
160
161 cargo fetch
162
163 ## SEE ALSO
164 [cargo(1)](cargo.html), [cargo-update(1)](cargo-update.html), [cargo-generate-lockfile(1)](cargo-generate-lockfile.html)