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       --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       --release
148           Build optimized artifacts with the release profile. See the
149           PROFILES section for details on how this affects profile selection.
150
151   Output Options
152       --target-dir directory
153           Directory for all generated artifacts and intermediate files. May
154           also be specified with the CARGO_TARGET_DIR environment variable,
155           or the build.target-dir config value
156           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
157           to target in the root of the workspace.
158
159       --out-dir directory
160           Copy final artifacts to this directory.
161
162           This option is unstable and available only on the nightly channel
163           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
164           requires the -Z unstable-options flag to enable. See
165           https://github.com/rust-lang/cargo/issues/6790 for more
166           information.
167
168   Display Options
169       -v, --verbose
170           Use verbose output. May be specified twice for "very verbose"
171           output which includes extra output such as dependency warnings and
172           build script output. May also be specified with the term.verbose
173           config value
174           <https://doc.rust-lang.org/cargo/reference/config.html>.
175
176       -q, --quiet
177           No output printed to stdout.
178
179       --color when
180           Control when colored output is used. Valid values:
181
182           ·  auto (default): Automatically detect if color support is
183               available on the terminal.
184
185           ·  always: Always display colors.
186
187           ·  never: Never display colors.
188
189           May also be specified with the term.color config value
190           <https://doc.rust-lang.org/cargo/reference/config.html>.
191
192       --message-format fmt
193           The output format for diagnostic messages. Can be specified
194           multiple times and consists of comma-separated values. Valid
195           values:
196
197           ·  human (default): Display in a human-readable text format.
198
199           ·  short: Emit shorter, human-readable text messages.
200
201           ·  json: Emit JSON messages to stdout. See the reference
202               <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
203               for more details.
204
205           ·  json-diagnostic-short: Ensure the rendered field of JSON
206               messages contains the "short" rendering from rustc.
207
208           ·  json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
209               messages contains embedded ANSI color codes for respecting
210               rustc's default color scheme.
211
212           ·  json-render-diagnostics: Instruct Cargo to not include rustc
213               diagnostics in in JSON messages printed, but instead Cargo
214               itself should render the JSON diagnostics coming from rustc.
215               Cargo's own JSON diagnostics and others coming from rustc are
216               still emitted.
217
218       --build-plan
219           Outputs a series of JSON messages to stdout that indicate the
220           commands to run the build.
221
222           This option is unstable and available only on the nightly channel
223           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
224           requires the -Z unstable-options flag to enable. See
225           <https://github.com/rust-lang/cargo/issues/5579> for more
226           information.
227
228   Manifest Options
229       --manifest-path path
230           Path to the Cargo.toml file. By default, Cargo searches for the
231           Cargo.toml file in the current directory or any parent directory.
232
233       --frozen, --locked
234           Either of these flags requires that the Cargo.lock file is
235           up-to-date. If the lock file is missing, or it needs to be updated,
236           Cargo will exit with an error. The --frozen flag also prevents
237           Cargo from attempting to access the network to determine if it is
238           out-of-date.
239
240           These may be used in environments where you want to assert that the
241           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
242           network access.
243
244       --offline
245           Prevents Cargo from accessing the network for any reason. Without
246           this flag, Cargo will stop with an error if it needs to access the
247           network and the network is not available. With this flag, Cargo
248           will attempt to proceed without the network if possible.
249
250           Beware that this may result in different dependency resolution than
251           online mode. Cargo will restrict itself to crates that are
252           downloaded locally, even if there might be a newer version as
253           indicated in the local copy of the index. See the cargo-fetch(1)
254           command to download dependencies before going offline.
255
256           May also be specified with the net.offline config value
257           <https://doc.rust-lang.org/cargo/reference/config.html>.
258
259   Common Options
260       +toolchain
261           If Cargo has been installed with rustup, and the first argument to
262           cargo begins with +, it will be interpreted as a rustup toolchain
263           name (such as +stable or +nightly). See the rustup documentation
264           <https://rust-lang.github.io/rustup/overrides.html> for more
265           information about how toolchain overrides work.
266
267       -h, --help
268           Prints help information.
269
270       -Z flag
271           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
272           details.
273
274   Miscellaneous Options
275       -j N, --jobs N
276           Number of parallel jobs to run. May also be specified with the
277           build.jobs config value
278           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
279           to the number of CPUs.
280

PROFILES

282       Profiles may be used to configure compiler options such as optimization
283       levels and debug settings. See the reference
284       <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
285       details.
286
287       Profile selection depends on the target and crate being built. By
288       default the dev or test profiles are used. If the --release flag is
289       given, then the release or bench profiles are used.
290
291
292       ┌────────────────────┬─────────────────┬───────────────────┐
293       │Target              │ Default Profile │ --release Profile │
294       ├────────────────────┼─────────────────┼───────────────────┤
295       │lib, bin, example   │ dev             release           
296       ├────────────────────┼─────────────────┼───────────────────┤
297       │test, bench, or any │ test            bench             
298       │target in "test" or │                 │                   │
299       │"bench" mode        │                 │                   │
300       └────────────────────┴─────────────────┴───────────────────┘
301
302       Dependencies use the dev/release profiles.
303

ENVIRONMENT

305       See the reference
306       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
307       for details on environment variables that Cargo reads.
308

EXIT STATUS

310       ·  0: Cargo succeeded.
311
312       ·  101: Cargo failed to complete.
313

EXAMPLES

315        1. Build the local package and all of its dependencies:
316
317               cargo build
318
319        2. Build with optimizations:
320
321               cargo build --release
322

SEE ALSO

324       cargo(1), cargo-rustc(1)
325
326
327
328                                                                CARGO-BUILD(1)
Impressum