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

ENVIRONMENT

327       See the reference
328       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
329       for details on environment variables that Cargo reads.
330

EXIT STATUS

3320: Cargo succeeded.
333
334101: Cargo failed to complete.
335

EXAMPLES

337        1. Build the local package and all of its dependencies:
338
339               cargo build
340
341        2. Build with optimizations:
342
343               cargo build --release
344

SEE ALSO

346       cargo(1), cargo-rustc(1)
347
348
349
350                                                                CARGO-BUILD(1)
Impressum