cargo 0.40.0

Cargo, a package manager for Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
'\" t
.\"     Title: cargo-rustc
.\"    Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8
.\"      Date: 2019-06-07
.\"    Manual: \ \&
.\"    Source: \ \&
.\"  Language: English
.\"
.TH "CARGO\-RUSTC" "1" "2019-06-07" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.ss \n[.ss] 0
.nh
.ad l
.de URL
\fI\\$2\fP <\\$1>\\$3
..
.als MTO URL
.if \n[.g] \{\
.  mso www.tmac
.  am URL
.    ad l
.  .
.  am MTO
.    ad l
.  .
.  LINKSTYLE blue R < >
.\}
.SH "NAME"
cargo\-rustc \- Compile the current package, and pass extra options to the compiler
.SH "SYNOPSIS"
.sp
\fBcargo rustc [\fIOPTIONS\fP] [\-\- \fIARGS\fP]\fP
.SH "DESCRIPTION"
.sp
The specified target for the current package (or package specified by \fB\-p\fP if
provided) will be compiled along with all of its dependencies. The specified
\fIARGS\fP will all be passed to the final compiler invocation, not any of the
dependencies. Note that the compiler will still unconditionally receive
arguments such as \fB\-L\fP, \fB\-\-extern\fP, and \fB\-\-crate\-type\fP, and the specified
\fIARGS\fP will simply be added to the compiler invocation.
.sp
See \c
.URL "https://doc.rust\-lang.org/rustc/index.html" "" " "
for documentation on rustc
flags.
.sp
This command requires that only one target is being compiled when additional
arguments are provided. If more than one target is available for the current
package the filters of \fB\-\-lib\fP, \fB\-\-bin\fP, etc, must be used to select which
target is compiled.
To pass flags to all compiler processes spawned by Cargo, use the \fBRUSTFLAGS\fP
environment variable or the \fBbuild.rustflags\fP
.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
.SH "OPTIONS"
.SS "Package Selection"
.sp
By default, the package in the current working directory is selected. The \fB\-p\fP
flag can be used to choose a different package in a workspace.
.sp
\fB\-p\fP \fISPEC\fP, \fB\-\-package\fP \fISPEC\fP
.RS 4
The package to build. See \fBcargo\-pkgid\fP(1) for
the SPEC format.
.RE
.SS "Target Selection"
.sp
When no target selection options are given, \fBcargo rustc\fP will build all
binary and library targets of the selected package.
.sp
Passing target selection flags will build only the
specified targets.
.sp
\fB\-\-lib\fP
.RS 4
Build the package\(cqs library.
.RE
.sp
\fB\-\-bin\fP \fINAME\fP...
.RS 4
Build the specified binary. This flag may be specified multiple times.
.RE
.sp
\fB\-\-bins\fP
.RS 4
Build all binary targets.
.RE
.sp
\fB\-\-example\fP \fINAME\fP...
.RS 4
Build the specified example. This flag may be specified multiple times.
.RE
.sp
\fB\-\-examples\fP
.RS 4
Build all example targets.
.RE
.sp
\fB\-\-test\fP \fINAME\fP...
.RS 4
Build the specified integration test. This flag may be specified multiple
times.
.RE
.sp
\fB\-\-tests\fP
.RS 4
Build all targets in test mode that have the \fBtest = true\fP manifest
flag set. By default this includes the library and binaries built as
unittests, and integration tests. Be aware that this will also build any
required dependencies, so the lib target may be built twice (once as a
unittest, and once as a dependency for binaries, integration tests, etc.).
Targets may be enabled or disabled by setting the \fBtest\fP flag in the
manifest settings for the target.
.RE
.sp
\fB\-\-bench\fP \fINAME\fP...
.RS 4
Build the specified benchmark. This flag may be specified multiple times.
.RE
.sp
\fB\-\-benches\fP
.RS 4
Build all targets in benchmark mode that have the \fBbench = true\fP
manifest flag set. By default this includes the library and binaries built
as benchmarks, and bench targets. Be aware that this will also build any
required dependencies, so the lib target may be built twice (once as a
benchmark, and once as a dependency for binaries, benchmarks, etc.).
Targets may be enabled or disabled by setting the \fBbench\fP flag in the
manifest settings for the target.
.RE
.sp
\fB\-\-all\-targets\fP
.RS 4
Build all targets. This is equivalent to specifying \fB\-\-lib \-\-bins
\-\-tests \-\-benches \-\-examples\fP.
.RE
.SS "Feature Selection"
.sp
When no feature options are given, the \fBdefault\fP feature is activated for
every selected package.
.sp
\fB\-\-features\fP \fIFEATURES\fP
.RS 4
Space or comma separated list of features to activate. These features only
apply to the current directory\(cqs package. Features of direct dependencies
may be enabled with \fB<dep\-name>/<feature\-name>\fP syntax.
.RE
.sp
\fB\-\-all\-features\fP
.RS 4
Activate all available features of all selected packages.
.RE
.sp
\fB\-\-no\-default\-features\fP
.RS 4
Do not activate the \fBdefault\fP feature of the current directory\(cqs
package.
.RE
.SS "Compilation Options"
.sp
\fB\-\-target\fP \fITRIPLE\fP
.RS 4
Build for the given architecture. The default is the host
architecture. The general format of the triple is
\fB<arch><sub>\-<vendor>\-<sys>\-<abi>\fP. Run \fBrustc \-\-print target\-list\fP for a
list of supported targets.
.sp
This may also be specified with the \fBbuild.target\fP
.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
.RE
.sp
\fB\-\-release\fP
.RS 4
Build optimized artifacts with the \fBrelease\fP profile. See the
PROFILES section for details on how this affects profile selection.
.RE
.SS "Output Options"
.sp
\fB\-\-target\-dir\fP \fIDIRECTORY\fP
.RS 4
Directory for all generated artifacts and intermediate files. May also be
specified with the \fBCARGO_TARGET_DIR\fP environment variable, or the
\fBbuild.target\-dir\fP \c
.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
Defaults
to \fBtarget\fP in the root of the workspace.
.RE
.SS "Display Options"
.sp
\fB\-v\fP, \fB\-\-verbose\fP
.RS 4
Use verbose output. May be specified twice for "very verbose" output which
includes extra output such as dependency warnings and build script output.
May also be specified with the \fBterm.verbose\fP
.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
.RE
.sp
\fB\-q\fP, \fB\-\-quiet\fP
.RS 4
No output printed to stdout.
.RE
.sp
\fB\-\-color\fP \fIWHEN\fP
.RS 4
Control when colored output is used. Valid values:
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.  sp -1
.  IP \(bu 2.3
.\}
\fBauto\fP (default): Automatically detect if color support is available on the
terminal.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.  sp -1
.  IP \(bu 2.3
.\}
\fBalways\fP: Always display colors.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.  sp -1
.  IP \(bu 2.3
.\}
\fBnever\fP: Never display colors.
.RE
.sp
May also be specified with the \fBterm.color\fP
.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
.RE
.sp
\fB\-\-message\-format\fP \fIFMT\fP
.RS 4
The output format for diagnostic messages. Can be specified multiple times
and consists of comma\-separated values. Valid values:
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.  sp -1
.  IP \(bu 2.3
.\}
\fBhuman\fP (default): Display in a human\-readable text format.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.  sp -1
.  IP \(bu 2.3
.\}
\fBshort\fP: Emit shorter, human\-readable text messages.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.  sp -1
.  IP \(bu 2.3
.\}
\fBjson\fP: Emit JSON messages to stdout.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.  sp -1
.  IP \(bu 2.3
.\}
\fBjson\-diagnostic\-short\fP: Ensure the \fBrendered\fP field of JSON messages contains
the "short" rendering from rustc.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.  sp -1
.  IP \(bu 2.3
.\}
\fBjson\-diagnostic\-rendered\-ansi\fP: Ensure the \fBrendered\fP field of JSON messages
contains embedded ANSI color codes for respecting rustc\(cqs default color
scheme.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.  sp -1
.  IP \(bu 2.3
.\}
\fBjson\-render\-diagnostics\fP: Instruct Cargo to not include rustc diagnostics in
in JSON messages printed, but instead Cargo itself should render the
JSON diagnostics coming from rustc. Cargo\(cqs own JSON diagnostics and others
coming from rustc are still emitted.
.RE
.RE
.SS "Manifest Options"
.sp
\fB\-\-manifest\-path\fP \fIPATH\fP
.RS 4
Path to the \fBCargo.toml\fP file. By default, Cargo searches in the current
directory or any parent directory for the \fBCargo.toml\fP file.
.RE
.sp
\fB\-\-frozen\fP, \fB\-\-locked\fP
.RS 4
Either of these flags requires that the \fBCargo.lock\fP file is
up\-to\-date. If the lock file is missing, or it needs to be updated, Cargo will
exit with an error. The \fB\-\-frozen\fP flag also prevents Cargo from
attempting to access the network to determine if it is out\-of\-date.
.sp
These may be used in environments where you want to assert that the
\fBCargo.lock\fP file is up\-to\-date (such as a CI build) or want to avoid network
access.
.RE
.sp
\fB\-\-offline\fP
.RS 4
Prevents Cargo from accessing the network for any reason. Without this
flag, Cargo will stop with an error if it needs to access the network and
the network is not available. With this flag, Cargo will attempt to
proceed without the network if possible.
.sp
Beware that this may result in different dependency resolution than online
mode. Cargo will restrict itself to crates that are downloaded locally, even
if there might be a newer version as indicated in the local copy of the index.
See the \fBcargo\-fetch\fP(1) command to download dependencies before going
offline.
.sp
May also be specified with the \fBnet.offline\fP \c
.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
.RE
.SS "Common Options"
.sp
\fB\-h\fP, \fB\-\-help\fP
.RS 4
Prints help information.
.RE
.sp
\fB\-Z\fP \fIFLAG\fP...
.RS 4
Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fP for
details.
.RE
.SS "Miscellaneous Options"
.sp
\fB\-j\fP \fIN\fP, \fB\-\-jobs\fP \fIN\fP
.RS 4
Number of parallel jobs to run. May also be specified with the
\fBbuild.jobs\fP \c
.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
Defaults to
the number of CPUs.
.RE
.SH "PROFILES"
.sp
Profiles may be used to configure compiler options such as optimization levels
and debug settings. See
\c
.URL "https://doc.rust\-lang.org/cargo/reference/manifest.html#the\-profile\-sections" "the reference"
for more details.
.sp
Profile selection depends on the target and crate being built. By default the
\fBdev\fP or \fBtest\fP profiles are used. If the \fB\-\-release\fP flag is given, then the
\fBrelease\fP or \fBbench\fP profiles are used.
.TS
allbox tab(:);
lt lt lt.
T{
.sp
Target
T}:T{
.sp
Default Profile
T}:T{
.sp
\fB\-\-release\fP Profile
T}
T{
.sp
lib, bin, example
T}:T{
.sp
\fBdev\fP
T}:T{
.sp
\fBrelease\fP
T}
T{
.sp
test, bench, or any target
.br
in "test" or "bench" mode
T}:T{
.sp
\fBtest\fP
T}:T{
.sp
\fBbench\fP
T}
.TE
.sp
.sp
Dependencies use the \fBdev\fP/\fBrelease\fP profiles.
.SH "ENVIRONMENT"
.sp
See \c
.URL "https://doc.rust\-lang.org/cargo/reference/environment\-variables.html" "the reference" " "
for
details on environment variables that Cargo reads.
.SH "EXIT STATUS"
.sp
0
.RS 4
Cargo succeeded.
.RE
.sp
101
.RS 4
Cargo failed to complete.
.RE
.SH "EXAMPLES"
.sp
.RS 4
.ie n \{\
\h'-04' 1.\h'+01'\c
.\}
.el \{\
.  sp -1
.  IP " 1." 4.2
.\}
Check if your package (not including dependencies) uses unsafe code:
.sp
.if n .RS 4
.nf
cargo rustc \-\-lib \-\- \-D unsafe\-code
.fi
.if n .RE
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 2.\h'+01'\c
.\}
.el \{\
.  sp -1
.  IP " 2." 4.2
.\}
Try an experimental flag on the nightly compiler, such as this which prints
the size of every type:
.sp
.if n .RS 4
.nf
cargo rustc \-\-lib \-\- \-Z print\-type\-sizes
.fi
.if n .RE
.RE
.SH "SEE ALSO"
.sp
\fBcargo\fP(1), \fBcargo\-build\fP(1), \fBrustc\fP(1)