blob: eeb3d9805c289d45a2aba0a90bbd2aed5c00862e [file] [log] [blame]
Matthew Maurerbd398542019-09-05 16:25:08 -07001'\" t
2.\" Title: cargo-build
3.\" Author: [see the "AUTHOR(S)" section]
4.\" Generator: Asciidoctor 1.5.8
5.\" Date: 2019-05-08
6.\" Manual: \ \&
7.\" Source: \ \&
8.\" Language: English
9.\"
10.TH "CARGO\-BUILD" "1" "2019-05-08" "\ \&" "\ \&"
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 current working directory. In the root of a virtual workspace,
43all workspace members are selected (\fB\-\-all\fP is implied). Otherwise, only the
44package in the current directory will be selected. The default packages may be
45overridden with the \fBworkspace.default\-members\fP key in the root \fBCargo.toml\fP
46manifest.
47.sp
48\fB\-p\fP \fISPEC\fP..., \fB\-\-package\fP \fISPEC\fP...
49.RS 4
50Build only the specified packages. See \fBcargo\-pkgid\fP(1) for the
51SPEC format. This flag may be specified multiple times.
52.RE
53.sp
54\fB\-\-all\fP
55.RS 4
56Build all members in the workspace.
57.RE
58.sp
59\fB\-\-exclude\fP \fISPEC\fP...
60.RS 4
61Exclude the specified packages. Must be used in conjunction with the
62\fB\-\-all\fP flag. This flag may be specified multiple times.
63.RE
64.SS "Target Selection"
65.sp
66When no target selection options are given, \fBcargo build\fP will build all
67binary and library targets of the selected packages. Binaries are skipped if
68they have \fBrequired\-features\fP that are missing.
69.sp
70Passing target selection flags will build only the
71specified targets.
72.sp
73\fB\-\-lib\fP
74.RS 4
75Build the package\(cqs library.
76.RE
77.sp
78\fB\-\-bin\fP \fINAME\fP...
79.RS 4
80Build the specified binary. This flag may be specified multiple times.
81.RE
82.sp
83\fB\-\-bins\fP
84.RS 4
85Build all binary targets.
86.RE
87.sp
88\fB\-\-example\fP \fINAME\fP...
89.RS 4
90Build the specified example. This flag may be specified multiple times.
91.RE
92.sp
93\fB\-\-examples\fP
94.RS 4
95Build all example targets.
96.RE
97.sp
98\fB\-\-test\fP \fINAME\fP...
99.RS 4
100Build the specified integration test. This flag may be specified multiple
101times.
102.RE
103.sp
104\fB\-\-tests\fP
105.RS 4
106Build all targets in test mode that have the \fBtest = true\fP manifest
107flag set. By default this includes the library and binaries built as
108unittests, and integration tests. Be aware that this will also build any
109required dependencies, so the lib target may be built twice (once as a
110unittest, and once as a dependency for binaries, integration tests, etc.).
111Targets may be enabled or disabled by setting the \fBtest\fP flag in the
112manifest settings for the target.
113.RE
114.sp
115\fB\-\-bench\fP \fINAME\fP...
116.RS 4
117Build the specified benchmark. This flag may be specified multiple times.
118.RE
119.sp
120\fB\-\-benches\fP
121.RS 4
122Build all targets in benchmark mode that have the \fBbench = true\fP
123manifest flag set. By default this includes the library and binaries built
124as benchmarks, and bench targets. Be aware that this will also build any
125required dependencies, so the lib target may be built twice (once as a
126benchmark, and once as a dependency for binaries, benchmarks, etc.).
127Targets may be enabled or disabled by setting the \fBbench\fP flag in the
128manifest settings for the target.
129.RE
130.sp
131\fB\-\-all\-targets\fP
132.RS 4
133Build all targets. This is equivalent to specifying \fB\-\-lib \-\-bins
134\-\-tests \-\-benches \-\-examples\fP.
135.RE
136.SS "Feature Selection"
137.sp
138When no feature options are given, the \fBdefault\fP feature is activated for
139every selected package.
140.sp
141\fB\-\-features\fP \fIFEATURES\fP
142.RS 4
143Space or comma separated list of features to activate. These features only
144apply to the current directory\(cqs package. Features of direct dependencies
145may be enabled with \fB<dep\-name>/<feature\-name>\fP syntax.
146.RE
147.sp
148\fB\-\-all\-features\fP
149.RS 4
150Activate all available features of all selected packages.
151.RE
152.sp
153\fB\-\-no\-default\-features\fP
154.RS 4
155Do not activate the \fBdefault\fP feature of the current directory\(cqs
156package.
157.RE
158.SS "Compilation Options"
159.sp
160\fB\-\-target\fP \fITRIPLE\fP
161.RS 4
162Build for the given architecture. The default is the host
163architecture. The general format of the triple is
164\fB<arch><sub>\-<vendor>\-<sys>\-<abi>\fP. Run \fBrustc \-\-print target\-list\fP for a
165list of supported targets.
166.sp
167This may also be specified with the \fBbuild.target\fP
168.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
169.RE
170.sp
171\fB\-\-release\fP
172.RS 4
173Build optimized artifacts with the \fBrelease\fP profile. See the
174PROFILES section for details on how this affects profile selection.
175.RE
176.SS "Output Options"
177.sp
178\fB\-\-target\-dir\fP \fIDIRECTORY\fP
179.RS 4
180Directory for all generated artifacts and intermediate files. May also be
181specified with the \fBCARGO_TARGET_DIR\fP environment variable, or the
182\fBbuild.target\-dir\fP \c
183.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
184Defaults
185to \fBtarget\fP in the root of the workspace.
186.RE
187.sp
188\fB\-\-out\-dir\fP \fIDIRECTORY\fP
189.RS 4
190Copy final artifacts to this directory.
191.sp
192This option is unstable and available only on the
193\c
194.URL "https://doc.rust\-lang.org/book/appendix\-07\-nightly\-rust.html" "nightly channel"
195and requires the \fB\-Z unstable\-options\fP flag to enable.
196See \c
197.URL "https://github.com/rust\-lang/cargo/issues/6790" "" " "
198for more information.
199.RE
200.SS "Display Options"
201.sp
202\fB\-v\fP, \fB\-\-verbose\fP
203.RS 4
204Use verbose output. May be specified twice for "very verbose" output which
205includes extra output such as dependency warnings and build script output.
206May also be specified with the \fBterm.verbose\fP
207.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
208.RE
209.sp
210\fB\-q\fP, \fB\-\-quiet\fP
211.RS 4
212No output printed to stdout.
213.RE
214.sp
215\fB\-\-color\fP \fIWHEN\fP
216.RS 4
217Control when colored output is used. Valid values:
218.sp
219.RS 4
220.ie n \{\
221\h'-04'\(bu\h'+03'\c
222.\}
223.el \{\
224. sp -1
225. IP \(bu 2.3
226.\}
227\fBauto\fP (default): Automatically detect if color support is available on the
228terminal.
229.RE
230.sp
231.RS 4
232.ie n \{\
233\h'-04'\(bu\h'+03'\c
234.\}
235.el \{\
236. sp -1
237. IP \(bu 2.3
238.\}
239\fBalways\fP: Always display colors.
240.RE
241.sp
242.RS 4
243.ie n \{\
244\h'-04'\(bu\h'+03'\c
245.\}
246.el \{\
247. sp -1
248. IP \(bu 2.3
249.\}
250\fBnever\fP: Never display colors.
251.RE
252.sp
253May also be specified with the \fBterm.color\fP
254.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
255.RE
256.sp
257\fB\-\-message\-format\fP \fIFMT\fP
258.RS 4
259The output format for diagnostic messages. Valid values:
260.sp
261.RS 4
262.ie n \{\
263\h'-04'\(bu\h'+03'\c
264.\}
265.el \{\
266. sp -1
267. IP \(bu 2.3
268.\}
269\fBhuman\fP (default): Display in a human\-readable text format.
270.RE
271.sp
272.RS 4
273.ie n \{\
274\h'-04'\(bu\h'+03'\c
275.\}
276.el \{\
277. sp -1
278. IP \(bu 2.3
279.\}
280\fBjson\fP: Emit JSON messages to stdout.
281.RE
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\fBshort\fP: Emit shorter, human\-readable text messages.
292.RE
293.RE
294.sp
295\fB\-\-build\-plan\fP
296.RS 4
297Outputs a series of JSON messages to stdout that indicate the commands to
298run the build.
299.sp
300This option is unstable and available only on the
301\c
302.URL "https://doc.rust\-lang.org/book/appendix\-07\-nightly\-rust.html" "nightly channel"
303and requires the \fB\-Z unstable\-options\fP flag to enable.
304See \c
305.URL "https://github.com/rust\-lang/cargo/issues/5579" "" " "
306for more information.
307.RE
308.SS "Manifest Options"
309.sp
310\fB\-\-manifest\-path\fP \fIPATH\fP
311.RS 4
312Path to the \fBCargo.toml\fP file. By default, Cargo searches in the current
313directory or any parent directory for the \fBCargo.toml\fP file.
314.RE
315.sp
316\fB\-\-frozen\fP, \fB\-\-locked\fP
317.RS 4
318Either of these flags requires that the \fBCargo.lock\fP file is
319up\-to\-date. If the lock file is missing, or it needs to be updated, Cargo will
320exit with an error. The \fB\-\-frozen\fP flag also prevents Cargo from
321attempting to access the network to determine if it is out\-of\-date.
322.sp
323These may be used in environments where you want to assert that the
324\fBCargo.lock\fP file is up\-to\-date (such as a CI build) or want to avoid network
325access.
326.RE
327.sp
328\fB\-\-offline\fP
329.RS 4
330Prevents Cargo from accessing the network for any reason. Without this
331flag, Cargo will stop with an error if it needs to access the network and
332the network is not available. With this flag, Cargo will attempt to
333proceed without the network if possible.
334.sp
335Beware that this may result in different dependency resolution than online
336mode. Cargo will restrict itself to crates that are downloaded locally, even
337if there might be a newer version as indicated in the local copy of the index.
338See the \fBcargo\-fetch\fP(1) command to download dependencies before going
339offline.
340.sp
341May also be specified with the \fBnet.offline\fP \c
342.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
343.RE
344.SS "Common Options"
345.sp
346\fB\-h\fP, \fB\-\-help\fP
347.RS 4
348Prints help information.
349.RE
350.sp
351\fB\-Z\fP \fIFLAG\fP...
352.RS 4
353Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fP for
354details.
355.RE
356.SS "Miscellaneous Options"
357.sp
358\fB\-j\fP \fIN\fP, \fB\-\-jobs\fP \fIN\fP
359.RS 4
360Number of parallel jobs to run. May also be specified with the
361\fBbuild.jobs\fP \c
362.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
363Defaults to
364the number of CPUs.
365.RE
366.SH "PROFILES"
367.sp
368Profiles may be used to configure compiler options such as optimization levels
369and debug settings. See
370\c
371.URL "https://doc.rust\-lang.org/cargo/reference/manifest.html#the\-profile\-sections" "the reference"
372for more details.
373.sp
374Profile selection depends on the target and crate being built. By default the
375\fBdev\fP or \fBtest\fP profiles are used. If the \fB\-\-release\fP flag is given, then the
376\fBrelease\fP or \fBbench\fP profiles are used.
377.TS
378allbox tab(:);
379lt lt lt.
380T{
381.sp
382Target
383T}:T{
384.sp
385Default Profile
386T}:T{
387.sp
388\fB\-\-release\fP Profile
389T}
390T{
391.sp
392lib, bin, example
393T}:T{
394.sp
395\fBdev\fP
396T}:T{
397.sp
398\fBrelease\fP
399T}
400T{
401.sp
402test, bench, or any target
403.br
404in "test" or "bench" mode
405T}:T{
406.sp
407\fBtest\fP
408T}:T{
409.sp
410\fBbench\fP
411T}
412.TE
413.sp
414.sp
415Dependencies use the \fBdev\fP/\fBrelease\fP profiles.
416.SH "ENVIRONMENT"
417.sp
418See \c
419.URL "https://doc.rust\-lang.org/cargo/reference/environment\-variables.html" "the reference" " "
420for
421details on environment variables that Cargo reads.
422.SH "EXIT STATUS"
423.sp
4240
425.RS 4
426Cargo succeeded.
427.RE
428.sp
429101
430.RS 4
431Cargo failed to complete.
432.RE
433.SH "EXAMPLES"
434.sp
435.RS 4
436.ie n \{\
437\h'-04' 1.\h'+01'\c
438.\}
439.el \{\
440. sp -1
441. IP " 1." 4.2
442.\}
443Build the local package and all of its dependencies:
444.sp
445.if n .RS 4
446.nf
447cargo build
448.fi
449.if n .RE
450.RE
451.sp
452.RS 4
453.ie n \{\
454\h'-04' 2.\h'+01'\c
455.\}
456.el \{\
457. sp -1
458. IP " 2." 4.2
459.\}
460Build with optimizations:
461.sp
462.if n .RS 4
463.nf
464cargo build \-\-release
465.fi
466.if n .RE
467.RE
468.SH "SEE ALSO"
469.sp
470\fBcargo\fP(1), \fBcargo\-rustc\fP(1)