1CARGO-BUILD(1)              General Commands Manual             CARGO-BUILD(1)
2
3
4

NAME

6       cargo-build - Compile the current package
7

SYNOPSIS

9       cargo build [options]
10

DESCRIPTION

12       Compile local packages and all of their dependencies.
13

OPTIONS

15   Package Selection
16       By default, when no package selection options are given, the packages
17       selected depend on the selected manifest file (based on the current
18       working directory if --manifest-path is not given). If the manifest is
19       the root of a workspace then the workspaces default members are
20       selected, otherwise only the package defined by the manifest will be
21       selected.
22
23       The default members of a workspace can be set explicitly with the
24       workspace.default-members key in the root manifest. If this is not set,
25       a virtual workspace will include all workspace members (equivalent to
26       passing --workspace), and a non-virtual workspace will include only the
27       root crate itself.
28
29       -p spec..., --package spec...
30           Build only the specified packages. See cargo-pkgid(1) for the SPEC
31           format. This flag may be specified multiple times and supports
32           common Unix glob patterns like *, ? and []. However, to avoid your
33           shell accidentally expanding glob patterns before Cargo handles
34           them, you must use single quotes or double quotes around each
35           pattern.
36
37       --workspace
38           Build all members in the workspace.
39
40       --all
41           Deprecated alias for --workspace.
42
43       --exclude SPEC...
44           Exclude the specified packages. Must be used in conjunction with
45           the --workspace flag. This flag may be specified multiple times and
46           supports common Unix glob patterns like *, ? and []. However, to
47           avoid your shell accidentally expanding glob patterns before Cargo
48           handles them, you must use single quotes or double quotes around
49           each pattern.
50
51   Target Selection
52       When no target selection options are given, cargo build will build all
53       binary and library targets of the selected packages. Binaries are
54       skipped if they have required-features that are missing.
55
56       Binary targets are automatically built if there is an integration test
57       or benchmark being selected to build. This allows an integration test
58       to execute the binary to exercise and test its behavior. The
59       CARGO_BIN_EXE_<name> environment variable
60       <https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates>
61       is set when the integration test is built so that it can use the env
62       macro <https://doc.rust-lang.org/std/macro.env.html> to locate the
63       executable.
64
65       Passing target selection flags will build only the specified targets.
66
67       Note that --bin, --example, --test and --bench flags also support
68       common Unix glob patterns like *, ? and []. However, to avoid your
69       shell accidentally expanding glob patterns before Cargo handles them,
70       you must use single quotes or double quotes around each glob pattern.
71
72       --lib
73           Build the package's library.
74
75       --bin name...
76           Build the specified binary. This flag may be specified multiple
77           times and supports common Unix glob patterns.
78
79       --bins
80           Build all binary targets.
81
82       --example name...
83           Build the specified example. This flag may be specified multiple
84           times and supports common Unix glob patterns.
85
86       --examples
87           Build all example targets.
88
89       --test name...
90           Build the specified integration test. This flag may be specified
91           multiple times and supports common Unix glob patterns.
92
93       --tests
94           Build all targets in test mode that have the test = true manifest
95           flag set. By default this includes the library and binaries built
96           as unittests, and integration tests. Be aware that this will also
97           build any required dependencies, so the lib target may be built
98           twice (once as a unittest, and once as a dependency for binaries,
99           integration tests, etc.). Targets may be enabled or disabled by
100           setting the test flag in the manifest settings for the target.
101
102       --bench name...
103           Build the specified benchmark. This flag may be specified multiple
104           times and supports common Unix glob patterns.
105
106       --benches
107           Build all targets in benchmark mode that have the bench = true
108           manifest flag set. By default this includes the library and
109           binaries built as benchmarks, and bench targets. Be aware that this
110           will also build any required dependencies, so the lib target may be
111           built twice (once as a benchmark, and once as a dependency for
112           binaries, benchmarks, etc.). Targets may be enabled or disabled by
113           setting the bench flag in the manifest settings for the target.
114
115       --all-targets
116           Build all targets. This is equivalent to specifying --lib --bins
117           --tests --benches --examples.
118
119   Feature Selection
120       The feature flags allow you to control which features are enabled. When
121       no feature options are given, the default feature is activated for
122       every selected package.
123
124       See the features documentation
125       <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>
126       for more details.
127
128       -F features, --features features
129           Space or comma separated list of features to activate. Features of
130           workspace members may be enabled with package-name/feature-name
131           syntax. This flag may be specified multiple times, which enables
132           all specified features.
133
134       --all-features
135           Activate all available features of all selected packages.
136
137       --no-default-features
138           Do not activate the default feature of the selected packages.
139
140   Compilation Options
141       --target triple
142           Build for the given architecture. The default is the host
143           architecture. The general format of the triple is
144           <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
145           a list of supported targets. This flag may be specified multiple
146           times.
147
148           This may also be specified with the build.target config value
149           <https://doc.rust-lang.org/cargo/reference/config.html>.
150
151           Note that specifying this flag makes Cargo run in a different mode
152           where the target artifacts are placed in a separate directory. See
153           the build cache
154           <https://doc.rust-lang.org/cargo/guide/build-cache.html>
155           documentation for more details.
156
157       -r, --release
158           Build optimized artifacts with the release profile. See also the
159           --profile option for choosing a specific profile by name.
160
161       --profile name
162           Build with the given profile. See the the reference
163           <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
164           details on profiles.
165
166       --ignore-rust-version
167           Build the target even if the selected Rust compiler is older than
168           the required Rust version as configured in the project's
169           rust-version field.
170
171       --timings=fmts
172           Output information how long each compilation takes, and track
173           concurrency information over time. Accepts an optional
174           comma-separated list of output formats; --timings without an
175           argument will default to --timings=html. Specifying an output
176           format (rather than the default) is unstable and requires
177           -Zunstable-options. Valid output formats:
178
179html (unstable, requires -Zunstable-options): Write a
180               human-readable file cargo-timing.html to the
181               target/cargo-timings directory with a report of the
182               compilation. Also write a report to the same directory with a
183               timestamp in the filename if you want to look at older runs.
184               HTML output is suitable for human consumption only, and does
185               not provide machine-readable timing data.
186
187json (unstable, requires -Zunstable-options): Emit
188               machine-readable JSON information about timing information.
189
190   Output Options
191       --target-dir directory
192           Directory for all generated artifacts and intermediate files. May
193           also be specified with the CARGO_TARGET_DIR environment variable,
194           or the build.target-dir config value
195           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
196           to target in the root of the workspace.
197
198       --out-dir directory
199           Copy final artifacts to this directory.
200
201           This option is unstable and available only on the nightly channel
202           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
203           requires the -Z unstable-options flag to enable. See
204           <https://github.com/rust-lang/cargo/issues/6790> for more
205           information.
206
207   Display Options
208       -v, --verbose
209           Use verbose output. May be specified twice for "very verbose"
210           output which includes extra output such as dependency warnings and
211           build script output. May also be specified with the term.verbose
212           config value
213           <https://doc.rust-lang.org/cargo/reference/config.html>.
214
215       -q, --quiet
216           Do not print cargo log messages. May also be specified with the
217           term.quiet config value
218           <https://doc.rust-lang.org/cargo/reference/config.html>.
219
220       --color when
221           Control when colored output is used. Valid values:
222
223auto (default): Automatically detect if color support is
224               available on the terminal.
225
226always: Always display colors.
227
228never: Never display colors.
229
230           May also be specified with the term.color config value
231           <https://doc.rust-lang.org/cargo/reference/config.html>.
232
233       --message-format fmt
234           The output format for diagnostic messages. Can be specified
235           multiple times and consists of comma-separated values. Valid
236           values:
237
238human (default): Display in a human-readable text format.
239               Conflicts with short and json.
240
241short: Emit shorter, human-readable text messages. Conflicts
242               with human and json.
243
244json: Emit JSON messages to stdout. See the reference
245               <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
246               for more details. Conflicts with human and short.
247
248json-diagnostic-short: Ensure the rendered field of JSON
249               messages contains the "short" rendering from rustc. Cannot be
250               used with human or short.
251
252json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
253               messages contains embedded ANSI color codes for respecting
254               rustc's default color scheme. Cannot be used with human or
255               short.
256
257json-render-diagnostics: Instruct Cargo to not include rustc
258               diagnostics in JSON messages printed, but instead Cargo itself
259               should render the JSON diagnostics coming from rustc. Cargo's
260               own JSON diagnostics and others coming from rustc are still
261               emitted. Cannot be used with human or short.
262
263       --build-plan
264           Outputs a series of JSON messages to stdout that indicate the
265           commands to run the build.
266
267           This option is unstable and available only on the nightly channel
268           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
269           requires the -Z unstable-options flag to enable. See
270           <https://github.com/rust-lang/cargo/issues/5579> for more
271           information.
272
273   Manifest Options
274       --manifest-path path
275           Path to the Cargo.toml file. By default, Cargo searches for the
276           Cargo.toml file in the current directory or any parent directory.
277
278       --frozen, --locked
279           Either of these flags requires that the Cargo.lock file is
280           up-to-date. If the lock file is missing, or it needs to be updated,
281           Cargo will exit with an error. The --frozen flag also prevents
282           Cargo from attempting to access the network to determine if it is
283           out-of-date.
284
285           These may be used in environments where you want to assert that the
286           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
287           network access.
288
289       --offline
290           Prevents Cargo from accessing the network for any reason. Without
291           this flag, Cargo will stop with an error if it needs to access the
292           network and the network is not available. With this flag, Cargo
293           will attempt to proceed without the network if possible.
294
295           Beware that this may result in different dependency resolution than
296           online mode. Cargo will restrict itself to crates that are
297           downloaded locally, even if there might be a newer version as
298           indicated in the local copy of the index. See the cargo-fetch(1)
299           command to download dependencies before going offline.
300
301           May also be specified with the net.offline config value
302           <https://doc.rust-lang.org/cargo/reference/config.html>.
303
304   Common Options
305       +toolchain
306           If Cargo has been installed with rustup, and the first argument to
307           cargo begins with +, it will be interpreted as a rustup toolchain
308           name (such as +stable or +nightly). See the rustup documentation
309           <https://rust-lang.github.io/rustup/overrides.html> for more
310           information about how toolchain overrides work.
311
312       --config KEY=VALUE or PATH
313           Overrides a Cargo configuration value. The argument should be in
314           TOML syntax of KEY=VALUE, or provided as a path to an extra
315           configuration file. This flag may be specified multiple times. See
316           the command-line overrides section
317           <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
318           for more information.
319
320       -h, --help
321           Prints help information.
322
323       -Z flag
324           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
325           details.
326
327   Miscellaneous Options
328       -j N, --jobs N
329           Number of parallel jobs to run. May also be specified with the
330           build.jobs config value
331           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
332           to the number of logical CPUs. If negative, it sets the maximum
333           number of parallel jobs to the number of logical CPUs plus provided
334           value. Should not be 0.
335
336       --keep-going
337           Build as many crates in the dependency graph as possible, rather
338           than aborting the build on the first one that fails to build.
339           Unstable, requires -Zunstable-options.
340
341       --future-incompat-report
342           Displays a future-incompat report for any future-incompatible
343           warnings produced during execution of this command
344
345           See cargo-report(1)
346

ENVIRONMENT

348       See the reference
349       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
350       for details on environment variables that Cargo reads.
351

EXIT STATUS

3530: Cargo succeeded.
354
355101: Cargo failed to complete.
356

EXAMPLES

358        1. Build the local package and all of its dependencies:
359
360               cargo build
361
362        2. Build with optimizations:
363
364               cargo build --release
365

SEE ALSO

367       cargo(1), cargo-rustc(1)
368
369
370
371                                                                CARGO-BUILD(1)
Impressum