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