]> git.proxmox.com Git - rustc.git/blame - src/tools/cargo/src/etc/man/cargo-build.1
New upstream version 1.74.1+dfsg1
[rustc.git] / src / tools / cargo / src / etc / man / cargo-build.1
CommitLineData
0a29b90c
FG
1'\" t
2.TH "CARGO\-BUILD" "1"
3.nh
4.ad l
5.ss \n[.ss] 0
6.SH "NAME"
7cargo\-build \[em] Compile the current package
8.SH "SYNOPSIS"
9\fBcargo build\fR [\fIoptions\fR]
10.SH "DESCRIPTION"
11Compile local packages and all of their dependencies.
12.SH "OPTIONS"
13.SS "Package Selection"
14By default, when no package selection options are given, the packages selected
15depend on the selected manifest file (based on the current working directory if
16\fB\-\-manifest\-path\fR is not given). If the manifest is the root of a workspace then
17the workspaces default members are selected, otherwise only the package defined
18by the manifest will be selected.
19.sp
20The default members of a workspace can be set explicitly with the
21\fBworkspace.default\-members\fR key in the root manifest. If this is not set, a
22virtual workspace will include all workspace members (equivalent to passing
23\fB\-\-workspace\fR), and a non\-virtual workspace will include only the root crate itself.
24.sp
25\fB\-p\fR \fIspec\fR\[u2026],
26\fB\-\-package\fR \fIspec\fR\[u2026]
27.RS 4
28Build only the specified packages. See \fBcargo\-pkgid\fR(1) for the
29SPEC format. This flag may be specified multiple times and supports common Unix
30glob patterns like \fB*\fR, \fB?\fR and \fB[]\fR\&. However, to avoid your shell accidentally
31expanding glob patterns before Cargo handles them, you must use single quotes or
32double quotes around each pattern.
33.RE
34.sp
35\fB\-\-workspace\fR
36.RS 4
37Build all members in the workspace.
38.RE
39.sp
40\fB\-\-all\fR
41.RS 4
42Deprecated alias for \fB\-\-workspace\fR\&.
43.RE
44.sp
45\fB\-\-exclude\fR \fISPEC\fR\[u2026]
46.RS 4
47Exclude the specified packages. Must be used in conjunction with the
48\fB\-\-workspace\fR flag. This flag may be specified multiple times and supports
49common Unix glob patterns like \fB*\fR, \fB?\fR and \fB[]\fR\&. However, to avoid your shell
50accidentally expanding glob patterns before Cargo handles them, you must use
51single quotes or double quotes around each pattern.
52.RE
53.SS "Target Selection"
54When no target selection options are given, \fBcargo build\fR will build all
55binary and library targets of the selected packages. Binaries are skipped if
56they have \fBrequired\-features\fR that are missing.
57.sp
58Binary targets are automatically built if there is an integration test or
59benchmark being selected to build. This allows an integration
60test to execute the binary to exercise and test its behavior.
61The \fBCARGO_BIN_EXE_<name>\fR
62\fIenvironment variable\fR <https://doc.rust\-lang.org/cargo/reference/environment\-variables.html#environment\-variables\-cargo\-sets\-for\-crates>
63is set when the integration test is built so that it can use the
64\fI\f(BIenv\fI macro\fR <https://doc.rust\-lang.org/std/macro.env.html> to locate the
65executable.
66.sp
67Passing target selection flags will build only the specified
68targets.
69.sp
70Note that \fB\-\-bin\fR, \fB\-\-example\fR, \fB\-\-test\fR and \fB\-\-bench\fR flags also
71support common Unix glob patterns like \fB*\fR, \fB?\fR and \fB[]\fR\&. However, to avoid your
72shell accidentally expanding glob patterns before Cargo handles them, you must
73use single quotes or double quotes around each glob pattern.
74.sp
75\fB\-\-lib\fR
76.RS 4
77Build the package\[cq]s library.
78.RE
79.sp
80\fB\-\-bin\fR \fIname\fR\[u2026]
81.RS 4
82Build the specified binary. This flag may be specified multiple times
83and supports common Unix glob patterns.
84.RE
85.sp
86\fB\-\-bins\fR
87.RS 4
88Build all binary targets.
89.RE
90.sp
91\fB\-\-example\fR \fIname\fR\[u2026]
92.RS 4
93Build the specified example. This flag may be specified multiple times
94and supports common Unix glob patterns.
95.RE
96.sp
97\fB\-\-examples\fR
98.RS 4
99Build all example targets.
100.RE
101.sp
102\fB\-\-test\fR \fIname\fR\[u2026]
103.RS 4
104Build the specified integration test. This flag may be specified
105multiple times and supports common Unix glob patterns.
106.RE
107.sp
108\fB\-\-tests\fR
109.RS 4
110Build all targets in test mode that have the \fBtest = true\fR manifest
111flag set. By default this includes the library and binaries built as
112unittests, and integration tests. Be aware that this will also build any
113required dependencies, so the lib target may be built twice (once as a
114unittest, and once as a dependency for binaries, integration tests, etc.).
115Targets may be enabled or disabled by setting the \fBtest\fR flag in the
116manifest settings for the target.
117.RE
118.sp
119\fB\-\-bench\fR \fIname\fR\[u2026]
120.RS 4
121Build the specified benchmark. This flag may be specified multiple
122times and supports common Unix glob patterns.
123.RE
124.sp
125\fB\-\-benches\fR
126.RS 4
127Build all targets in benchmark mode that have the \fBbench = true\fR
128manifest flag set. By default this includes the library and binaries built
129as benchmarks, and bench targets. Be aware that this will also build any
130required dependencies, so the lib target may be built twice (once as a
131benchmark, and once as a dependency for binaries, benchmarks, etc.).
132Targets may be enabled or disabled by setting the \fBbench\fR flag in the
133manifest settings for the target.
134.RE
135.sp
136\fB\-\-all\-targets\fR
137.RS 4
138Build all targets. This is equivalent to specifying \fB\-\-lib \-\-bins \-\-tests \-\-benches \-\-examples\fR\&.
139.RE
140.SS "Feature Selection"
141The feature flags allow you to control which features are enabled. When no
142feature options are given, the \fBdefault\fR feature is activated for every
143selected package.
144.sp
145See \fIthe features documentation\fR <https://doc.rust\-lang.org/cargo/reference/features.html#command\-line\-feature\-options>
146for more details.
147.sp
148\fB\-F\fR \fIfeatures\fR,
149\fB\-\-features\fR \fIfeatures\fR
150.RS 4
151Space or comma separated list of features to activate. Features of workspace
152members may be enabled with \fBpackage\-name/feature\-name\fR syntax. This flag may
153be specified multiple times, which enables all specified features.
154.RE
155.sp
156\fB\-\-all\-features\fR
157.RS 4
158Activate all available features of all selected packages.
159.RE
160.sp
161\fB\-\-no\-default\-features\fR
162.RS 4
163Do not activate the \fBdefault\fR feature of the selected packages.
164.RE
165.SS "Compilation Options"
166.sp
167\fB\-\-target\fR \fItriple\fR
168.RS 4
169Build for the given architecture. The default is the host architecture. The general format of the triple is
170\fB<arch><sub>\-<vendor>\-<sys>\-<abi>\fR\&. Run \fBrustc \-\-print target\-list\fR for a
171list of supported targets. This flag may be specified multiple times.
172.sp
173This may also be specified with the \fBbuild.target\fR
174\fIconfig value\fR <https://doc.rust\-lang.org/cargo/reference/config.html>\&.
175.sp
176Note that specifying this flag makes Cargo run in a different mode where the
177target artifacts are placed in a separate directory. See the
178\fIbuild cache\fR <https://doc.rust\-lang.org/cargo/guide/build\-cache.html> documentation for more details.
179.RE
180.sp
181\fB\-r\fR,
182\fB\-\-release\fR
183.RS 4
184Build optimized artifacts with the \fBrelease\fR profile.
185See also the \fB\-\-profile\fR option for choosing a specific profile by name.
186.RE
187.sp
188\fB\-\-profile\fR \fIname\fR
189.RS 4
190Build with the given profile.
191See the \fIthe reference\fR <https://doc.rust\-lang.org/cargo/reference/profiles.html> for more details on profiles.
192.RE
193.sp
194\fB\-\-ignore\-rust\-version\fR
195.RS 4
196Build the target even if the selected Rust compiler is older than the
197required Rust version as configured in the project\[cq]s \fBrust\-version\fR field.
198.RE
199.sp
200\fB\-\-timings=\fR\fIfmts\fR
201.RS 4
202Output information how long each compilation takes, and track concurrency
203information over time. Accepts an optional comma\-separated list of output
204formats; \fB\-\-timings\fR without an argument will default to \fB\-\-timings=html\fR\&.
205Specifying an output format (rather than the default) is unstable and requires
206\fB\-Zunstable\-options\fR\&. Valid output formats:
207.sp
208.RS 4
209\h'-04'\(bu\h'+02'\fBhtml\fR (unstable, requires \fB\-Zunstable\-options\fR): Write a human\-readable file \fBcargo\-timing.html\fR to the
210\fBtarget/cargo\-timings\fR directory with a report of the compilation. Also write
211a report to the same directory with a timestamp in the filename if you want
212to look at older runs. HTML output is suitable for human consumption only,
213and does not provide machine\-readable timing data.
214.RE
215.sp
216.RS 4
217\h'-04'\(bu\h'+02'\fBjson\fR (unstable, requires \fB\-Zunstable\-options\fR): Emit machine\-readable JSON
218information about timing information.
219.RE
220.RE
221.SS "Output Options"
222.sp
223\fB\-\-target\-dir\fR \fIdirectory\fR
224.RS 4
225Directory for all generated artifacts and intermediate files. May also be
226specified with the \fBCARGO_TARGET_DIR\fR environment variable, or the
227\fBbuild.target\-dir\fR \fIconfig value\fR <https://doc.rust\-lang.org/cargo/reference/config.html>\&.
228Defaults to \fBtarget\fR in the root of the workspace.
229.RE
230.sp
231\fB\-\-out\-dir\fR \fIdirectory\fR
232.RS 4
233Copy final artifacts to this directory.
234.sp
235This option is unstable and available only on the
236\fInightly channel\fR <https://doc.rust\-lang.org/book/appendix\-07\-nightly\-rust.html>
237and requires the \fB\-Z unstable\-options\fR flag to enable.
238See <https://github.com/rust\-lang/cargo/issues/6790> for more information.
239.RE
240.SS "Display Options"
241.sp
242\fB\-v\fR,
243\fB\-\-verbose\fR
244.RS 4
245Use verbose output. May be specified twice for \[lq]very verbose\[rq] output which
246includes extra output such as dependency warnings and build script output.
247May also be specified with the \fBterm.verbose\fR
248\fIconfig value\fR <https://doc.rust\-lang.org/cargo/reference/config.html>\&.
249.RE
250.sp
251\fB\-q\fR,
252\fB\-\-quiet\fR
253.RS 4
254Do not print cargo log messages.
255May also be specified with the \fBterm.quiet\fR
256\fIconfig value\fR <https://doc.rust\-lang.org/cargo/reference/config.html>\&.
257.RE
258.sp
259\fB\-\-color\fR \fIwhen\fR
260.RS 4
261Control when colored output is used. Valid values:
262.sp
263.RS 4
264\h'-04'\(bu\h'+02'\fBauto\fR (default): Automatically detect if color support is available on the
265terminal.
266.RE
267.sp
268.RS 4
269\h'-04'\(bu\h'+02'\fBalways\fR: Always display colors.
270.RE
271.sp
272.RS 4
273\h'-04'\(bu\h'+02'\fBnever\fR: Never display colors.
274.RE
275.sp
276May also be specified with the \fBterm.color\fR
277\fIconfig value\fR <https://doc.rust\-lang.org/cargo/reference/config.html>\&.
278.RE
279.sp
280\fB\-\-message\-format\fR \fIfmt\fR
281.RS 4
282The output format for diagnostic messages. Can be specified multiple times
283and consists of comma\-separated values. Valid values:
284.sp
285.RS 4
286\h'-04'\(bu\h'+02'\fBhuman\fR (default): Display in a human\-readable text format. Conflicts with
287\fBshort\fR and \fBjson\fR\&.
288.RE
289.sp
290.RS 4
291\h'-04'\(bu\h'+02'\fBshort\fR: Emit shorter, human\-readable text messages. Conflicts with \fBhuman\fR
292and \fBjson\fR\&.
293.RE
294.sp
295.RS 4
296\h'-04'\(bu\h'+02'\fBjson\fR: Emit JSON messages to stdout. See
297\fIthe reference\fR <https://doc.rust\-lang.org/cargo/reference/external\-tools.html#json\-messages>
298for more details. Conflicts with \fBhuman\fR and \fBshort\fR\&.
299.RE
300.sp
301.RS 4
302\h'-04'\(bu\h'+02'\fBjson\-diagnostic\-short\fR: Ensure the \fBrendered\fR field of JSON messages contains
303the \[lq]short\[rq] rendering from rustc. Cannot be used with \fBhuman\fR or \fBshort\fR\&.
304.RE
305.sp
306.RS 4
307\h'-04'\(bu\h'+02'\fBjson\-diagnostic\-rendered\-ansi\fR: Ensure the \fBrendered\fR field of JSON messages
308contains embedded ANSI color codes for respecting rustc\[cq]s default color
309scheme. Cannot be used with \fBhuman\fR or \fBshort\fR\&.
310.RE
311.sp
312.RS 4
313\h'-04'\(bu\h'+02'\fBjson\-render\-diagnostics\fR: Instruct Cargo to not include rustc diagnostics
314in JSON messages printed, but instead Cargo itself should render the
315JSON diagnostics coming from rustc. Cargo\[cq]s own JSON diagnostics and others
316coming from rustc are still emitted. Cannot be used with \fBhuman\fR or \fBshort\fR\&.
317.RE
318.RE
319.sp
320\fB\-\-build\-plan\fR
321.RS 4
322Outputs a series of JSON messages to stdout that indicate the commands to run
323the build.
324.sp
325This option is unstable and available only on the
326\fInightly channel\fR <https://doc.rust\-lang.org/book/appendix\-07\-nightly\-rust.html>
327and requires the \fB\-Z unstable\-options\fR flag to enable.
328See <https://github.com/rust\-lang/cargo/issues/5579> for more information.
329.RE
330.SS "Manifest Options"
331.sp
332\fB\-\-manifest\-path\fR \fIpath\fR
333.RS 4
334Path to the \fBCargo.toml\fR file. By default, Cargo searches for the
335\fBCargo.toml\fR file in the current directory or any parent directory.
336.RE
337.sp
338\fB\-\-frozen\fR,
339\fB\-\-locked\fR
340.RS 4
341Either of these flags requires that the \fBCargo.lock\fR file is
342up\-to\-date. If the lock file is missing, or it needs to be updated, Cargo will
343exit with an error. The \fB\-\-frozen\fR flag also prevents Cargo from
344attempting to access the network to determine if it is out\-of\-date.
345.sp
346These may be used in environments where you want to assert that the
347\fBCargo.lock\fR file is up\-to\-date (such as a CI build) or want to avoid network
348access.
349.RE
350.sp
351\fB\-\-offline\fR
352.RS 4
353Prevents Cargo from accessing the network for any reason. Without this
354flag, Cargo will stop with an error if it needs to access the network and
355the network is not available. With this flag, Cargo will attempt to
356proceed without the network if possible.
357.sp
358Beware that this may result in different dependency resolution than online
359mode. Cargo will restrict itself to crates that are downloaded locally, even
360if there might be a newer version as indicated in the local copy of the index.
361See the \fBcargo\-fetch\fR(1) command to download dependencies before going
362offline.
363.sp
364May also be specified with the \fBnet.offline\fR \fIconfig value\fR <https://doc.rust\-lang.org/cargo/reference/config.html>\&.
365.RE
366.SS "Common Options"
367.sp
368\fB+\fR\fItoolchain\fR
369.RS 4
370If Cargo has been installed with rustup, and the first argument to \fBcargo\fR
371begins with \fB+\fR, it will be interpreted as a rustup toolchain name (such
372as \fB+stable\fR or \fB+nightly\fR).
373See the \fIrustup documentation\fR <https://rust\-lang.github.io/rustup/overrides.html>
374for more information about how toolchain overrides work.
375.RE
376.sp
377\fB\-\-config\fR \fIKEY=VALUE\fR or \fIPATH\fR
378.RS 4
379Overrides a Cargo configuration value. The argument should be in TOML syntax of \fBKEY=VALUE\fR,
380or provided as a path to an extra configuration file. This flag may be specified multiple times.
381See the \fIcommand\-line overrides section\fR <https://doc.rust\-lang.org/cargo/reference/config.html#command\-line\-overrides> for more information.
382.RE
383.sp
384\fB\-C\fR \fIPATH\fR
385.RS 4
386Changes the current working directory before executing any specified operations. This affects
387things like where cargo looks by default for the project manifest (\fBCargo.toml\fR), as well as
388the directories searched for discovering \fB\&.cargo/config.toml\fR, for example. This option must
389appear before the command name, for example \fBcargo \-C path/to/my\-project build\fR\&.
390.sp
391This option is only available on the \fInightly
392channel\fR <https://doc.rust\-lang.org/book/appendix\-07\-nightly\-rust.html> and
393requires the \fB\-Z unstable\-options\fR flag to enable (see
394\fI#10098\fR <https://github.com/rust\-lang/cargo/issues/10098>).
395.RE
396.sp
397\fB\-h\fR,
398\fB\-\-help\fR
399.RS 4
400Prints help information.
401.RE
402.sp
403\fB\-Z\fR \fIflag\fR
404.RS 4
405Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fR for details.
406.RE
407.SS "Miscellaneous Options"
408.sp
409\fB\-j\fR \fIN\fR,
410\fB\-\-jobs\fR \fIN\fR
411.RS 4
412Number of parallel jobs to run. May also be specified with the
413\fBbuild.jobs\fR \fIconfig value\fR <https://doc.rust\-lang.org/cargo/reference/config.html>\&. Defaults to
414the number of logical CPUs. If negative, it sets the maximum number of
fe692bf9
FG
415parallel jobs to the number of logical CPUs plus provided value. If
416a string \fBdefault\fR is provided, it sets the value back to defaults.
0a29b90c
FG
417Should not be 0.
418.RE
419.sp
420\fB\-\-keep\-going\fR
421.RS 4
422Build as many crates in the dependency graph as possible, rather than aborting
781aab86
FG
423the build on the first one that fails to build.
424.sp
425For example if the current package depends on dependencies \fBfails\fR and \fBworks\fR,
426one of which fails to build, \fBcargo build \-j1\fR may or may not build the
427one that succeeds (depending on which one of the two builds Cargo picked to run
428first), whereas \fBcargo build \-j1 \-\-keep\-going\fR would definitely run both
429builds, even if the one run first fails.
0a29b90c
FG
430.RE
431.sp
432\fB\-\-future\-incompat\-report\fR
433.RS 4
434Displays a future\-incompat report for any future\-incompatible warnings
435produced during execution of this command
436.sp
437See \fBcargo\-report\fR(1)
438.RE
439.SH "ENVIRONMENT"
440See \fIthe reference\fR <https://doc.rust\-lang.org/cargo/reference/environment\-variables.html> for
441details on environment variables that Cargo reads.
442.SH "EXIT STATUS"
443.sp
444.RS 4
445\h'-04'\(bu\h'+02'\fB0\fR: Cargo succeeded.
446.RE
447.sp
448.RS 4
449\h'-04'\(bu\h'+02'\fB101\fR: Cargo failed to complete.
450.RE
451.SH "EXAMPLES"
452.sp
453.RS 4
454\h'-04' 1.\h'+01'Build the local package and all of its dependencies:
455.sp
456.RS 4
457.nf
458cargo build
459.fi
460.RE
461.RE
462.sp
463.RS 4
464\h'-04' 2.\h'+01'Build with optimizations:
465.sp
466.RS 4
467.nf
468cargo build \-\-release
469.fi
470.RE
471.RE
472.SH "SEE ALSO"
473\fBcargo\fR(1), \fBcargo\-rustc\fR(1)