1CARGO-BUILD(1)                                                  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.
32
33       --workspace
34           Build all members in the workspace.
35
36       --all
37           Deprecated alias for --workspace.
38
39       --exclude SPEC...
40           Exclude the specified packages. Must be used in conjunction with
41           the --workspace flag. This flag may be specified multiple times.
42
43   Target Selection
44       When no target selection options are given, cargo build will build all
45       binary and library targets of the selected packages. Binaries are
46       skipped if they have required-features that are missing.
47
48       Passing target selection flags will build only the specified targets.
49
50       --lib
51           Build the package’s library.
52
53       --bin NAME...
54           Build the specified binary. This flag may be specified multiple
55           times.
56
57       --bins
58           Build all binary targets.
59
60       --example NAME...
61           Build the specified example. This flag may be specified multiple
62           times.
63
64       --examples
65           Build all example targets.
66
67       --test NAME...
68           Build the specified integration test. This flag may be specified
69           multiple times.
70
71       --tests
72           Build all targets in test mode that have the test = true manifest
73           flag set. By default this includes the library and binaries built
74           as unittests, and integration tests. Be aware that this will also
75           build any required dependencies, so the lib target may be built
76           twice (once as a unittest, and once as a dependency for binaries,
77           integration tests, etc.). Targets may be enabled or disabled by
78           setting the test flag in the manifest settings for the target.
79
80       --bench NAME...
81           Build the specified benchmark. This flag may be specified multiple
82           times.
83
84       --benches
85           Build all targets in benchmark mode that have the bench = true
86           manifest flag set. By default this includes the library and
87           binaries built as benchmarks, and bench targets. Be aware that this
88           will also build any required dependencies, so the lib target may be
89           built twice (once as a benchmark, and once as a dependency for
90           binaries, benchmarks, etc.). Targets may be enabled or disabled by
91           setting the bench flag in the manifest settings for the target.
92
93       --all-targets
94           Build all targets. This is equivalent to specifying --lib --bins
95           --tests --benches --examples.
96
97   Feature Selection
98       The feature flags allow you to control the enabled features for the
99       "current" package. The "current" package is the package in the current
100       directory, or the one specified in --manifest-path. If running in the
101       root of a virtual workspace, then the default features are selected for
102       all workspace members, or all features if --all-features is specified.
103
104       When no feature options are given, the default feature is activated for
105       every selected package.
106
107       --features FEATURES
108           Space or comma separated list of features to activate. These
109           features only apply to the current directory’s package. Features of
110           direct dependencies may be enabled with <dep-name>/<feature-name>
111           syntax. This flag may be specified multiple times, which enables
112           all specified features.
113
114       --all-features
115           Activate all available features of all selected packages.
116
117       --no-default-features
118           Do not activate the default feature of the current directory’s
119           package.
120
121   Compilation Options
122       --target TRIPLE
123           Build for the given architecture. The default is the host
124           architecture. The general format of the triple is
125           <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
126           a list of supported targets.
127
128           This may also be specified with the build.target config value
129           <https://doc.rust-lang.org/cargo/reference/config.html>.
130
131           Note that specifying this flag makes Cargo run in a different mode
132           where the target artifacts are placed in a separate directory. See
133           the build cache
134           <https://doc.rust-lang.org/cargo/guide/build-cache.html>
135           documentation for more details.
136
137       --release
138           Build optimized artifacts with the release profile. See the
139           PROFILES section for details on how this affects profile selection.
140
141   Output Options
142       --target-dir DIRECTORY
143           Directory for all generated artifacts and intermediate files. May
144           also be specified with the CARGO_TARGET_DIR environment variable,
145           or the build.target-dir config value
146           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
147           to target in the root of the workspace.
148
149       --out-dir DIRECTORY
150           Copy final artifacts to this directory.
151
152           This option is unstable and available only on the nightly channel
153           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
154           requires the -Z unstable-options flag to enable. See
155           https://github.com/rust-lang/cargo/issues/6790 for more
156           information.
157
158   Display Options
159       -v, --verbose
160           Use verbose output. May be specified twice for "very verbose"
161           output which includes extra output such as dependency warnings and
162           build script output. May also be specified with the term.verbose
163           config value
164           <https://doc.rust-lang.org/cargo/reference/config.html>.
165
166       -q, --quiet
167           No output printed to stdout.
168
169       --color WHEN
170           Control when colored output is used. Valid values:
171
172           ·   auto (default): Automatically detect if color support is
173               available on the terminal.
174
175           ·   always: Always display colors.
176
177           ·   never: Never display colors.
178
179           May also be specified with the term.color config value
180           <https://doc.rust-lang.org/cargo/reference/config.html>.
181
182       --message-format FMT
183           The output format for diagnostic messages. Can be specified
184           multiple times and consists of comma-separated values. Valid
185           values:
186
187           ·   human (default): Display in a human-readable text format.
188
189           ·   short: Emit shorter, human-readable text messages.
190
191           ·   json: Emit JSON messages to stdout. See the reference
192               <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
193               for more details.
194
195           ·   json-diagnostic-short: Ensure the rendered field of JSON
196               messages contains the "short" rendering from rustc.
197
198           ·   json-diagnostic-rendered-ansi: Ensure the rendered field of
199               JSON messages contains embedded ANSI color codes for respecting
200               rustc’s default color scheme.
201
202           ·   json-render-diagnostics: Instruct Cargo to not include rustc
203               diagnostics in in JSON messages printed, but instead Cargo
204               itself should render the JSON diagnostics coming from rustc.
205               Cargo’s own JSON diagnostics and others coming from rustc are
206               still emitted.
207
208       --build-plan
209           Outputs a series of JSON messages to stdout that indicate the
210           commands to run the build.
211
212           This option is unstable and available only on the nightly channel
213           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
214           requires the -Z unstable-options flag to enable. See
215           https://github.com/rust-lang/cargo/issues/5579 for more
216           information.
217
218   Manifest Options
219       --manifest-path PATH
220           Path to the Cargo.toml file. By default, Cargo searches for the
221           Cargo.toml file in the current directory or any parent directory.
222
223       --frozen, --locked
224           Either of these flags requires that the Cargo.lock file is
225           up-to-date. If the lock file is missing, or it needs to be updated,
226           Cargo will exit with an error. The --frozen flag also prevents
227           Cargo from attempting to access the network to determine if it is
228           out-of-date.
229
230           These may be used in environments where you want to assert that the
231           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
232           network access.
233
234       --offline
235           Prevents Cargo from accessing the network for any reason. Without
236           this flag, Cargo will stop with an error if it needs to access the
237           network and the network is not available. With this flag, Cargo
238           will attempt to proceed without the network if possible.
239
240           Beware that this may result in different dependency resolution than
241           online mode. Cargo will restrict itself to crates that are
242           downloaded locally, even if there might be a newer version as
243           indicated in the local copy of the index. See the cargo-fetch(1)
244           command to download dependencies before going offline.
245
246           May also be specified with the net.offline config value
247           <https://doc.rust-lang.org/cargo/reference/config.html>.
248
249   Common Options
250       -h, --help
251           Prints help information.
252
253       -Z FLAG...
254           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
255           details.
256
257   Miscellaneous Options
258       -j N, --jobs N
259           Number of parallel jobs to run. May also be specified with the
260           build.jobs config value
261           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
262           to the number of CPUs.
263

PROFILES

265       Profiles may be used to configure compiler options such as optimization
266       levels and debug settings. See the reference
267       <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
268       details.
269
270       Profile selection depends on the target and crate being built. By
271       default the dev or test profiles are used. If the --release flag is
272       given, then the release or bench profiles are used.
273
274       ┌────────────────────┬─────────────────┬───────────────────┐
275       │                    │                 │                   │
276       │Target              │ Default Profile │ --release Profile │
277       ├────────────────────┼─────────────────┼───────────────────┤
278       │                    │                 │                   │
279       │lib, bin, example   │ dev             release           
280       ├────────────────────┼─────────────────┼───────────────────┤
281       │                    │                 │                   │
282       │test, bench, or any │ test            bench             
283       │target              │                 │                   │
284       │in "test" or        │                 │                   │
285       │"bench" mode        │                 │                   │
286       └────────────────────┴─────────────────┴───────────────────┘
287
288       Dependencies use the dev/release profiles.
289

ENVIRONMENT

291       See the reference
292       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
293       for details on environment variables that Cargo reads.
294

EXIT STATUS

296       0
297           Cargo succeeded.
298
299       101
300           Cargo failed to complete.
301

EXAMPLES

303        1. Build the local package and all of its dependencies:
304
305               cargo build
306
307        2. Build with optimizations:
308
309               cargo build --release
310

SEE ALSO

312       cargo(1), cargo-rustc(1)
313
314
315
316                                  2019-09-05                    CARGO-BUILD(1)
Impressum