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 current working directory. In the root of a
18       virtual workspace, all workspace members are selected (--all is
19       implied). Otherwise, only the package in the current directory will be
20       selected. The default packages may be overridden with the
21       workspace.default-members key in the root Cargo.toml manifest.
22
23       -p SPEC..., --package SPEC...
24           Build only the specified packages. See cargo-pkgid(1) for the SPEC
25           format. This flag may be specified multiple times.
26
27       --all
28           Build all members in the workspace.
29
30       --exclude SPEC...
31           Exclude the specified packages. Must be used in conjunction with
32           the --all flag. This flag may be specified multiple times.
33
34   Target Selection
35       When no target selection options are given, cargo build will build all
36       binary and library targets of the selected packages. Binaries are
37       skipped if they have required-features that are missing.
38
39       Passing target selection flags will build only the specified targets.
40
41       --lib
42           Build the package’s library.
43
44       --bin NAME...
45           Build the specified binary. This flag may be specified multiple
46           times.
47
48       --bins
49           Build all binary targets.
50
51       --example NAME...
52           Build the specified example. This flag may be specified multiple
53           times.
54
55       --examples
56           Build all example targets.
57
58       --test NAME...
59           Build the specified integration test. This flag may be specified
60           multiple times.
61
62       --tests
63           Build all targets in test mode that have the test = true manifest
64           flag set. By default this includes the library and binaries built
65           as unittests, and integration tests. Be aware that this will also
66           build any required dependencies, so the lib target may be built
67           twice (once as a unittest, and once as a dependency for binaries,
68           integration tests, etc.). Targets may be enabled or disabled by
69           setting the test flag in the manifest settings for the target.
70
71       --bench NAME...
72           Build the specified benchmark. This flag may be specified multiple
73           times.
74
75       --benches
76           Build all targets in benchmark mode that have the bench = true
77           manifest flag set. By default this includes the library and
78           binaries built as benchmarks, and bench targets. Be aware that this
79           will also build any required dependencies, so the lib target may be
80           built twice (once as a benchmark, and once as a dependency for
81           binaries, benchmarks, etc.). Targets may be enabled or disabled by
82           setting the bench flag in the manifest settings for the target.
83
84       --all-targets
85           Build all targets. This is equivalent to specifying --lib --bins
86           --tests --benches --examples.
87
88   Feature Selection
89       When no feature options are given, the default feature is activated for
90       every selected package.
91
92       --features FEATURES
93           Space or comma separated list of features to activate. These
94           features only apply to the current directory’s package. Features of
95           direct dependencies may be enabled with <dep-name>/<feature-name>
96           syntax.
97
98       --all-features
99           Activate all available features of all selected packages.
100
101       --no-default-features
102           Do not activate the default feature of the current directory’s
103           package.
104
105   Compilation Options
106       --target TRIPLE
107           Build for the given architecture. The default is the host
108           architecture. The general format of the triple is
109           <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
110           a list of supported targets.
111
112           This may also be specified with the build.target config value
113           <https://doc.rust-lang.org/cargo/reference/config.html>.
114
115       --release
116           Build optimized artifacts with the release profile. See the
117           PROFILES section for details on how this affects profile selection.
118
119   Output Options
120       --target-dir DIRECTORY
121           Directory for all generated artifacts and intermediate files. May
122           also be specified with the CARGO_TARGET_DIR environment variable,
123           or the build.target-dir config value
124           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
125           to target in the root of the workspace.
126
127       --out-dir DIRECTORY
128           Copy final artifacts to this directory.
129
130           This option is unstable and available only on the nightly channel
131           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
132           requires the -Z unstable-options flag to enable. See
133           https://github.com/rust-lang/cargo/issues/6790 for more
134           information.
135
136   Display Options
137       -v, --verbose
138           Use verbose output. May be specified twice for "very verbose"
139           output which includes extra output such as dependency warnings and
140           build script output. May also be specified with the term.verbose
141           config value
142           <https://doc.rust-lang.org/cargo/reference/config.html>.
143
144       -q, --quiet
145           No output printed to stdout.
146
147       --color WHEN
148           Control when colored output is used. Valid values:
149
150           ·   auto (default): Automatically detect if color support is
151               available on the terminal.
152
153           ·   always: Always display colors.
154
155           ·   never: Never display colors.
156
157           May also be specified with the term.color config value
158           <https://doc.rust-lang.org/cargo/reference/config.html>.
159
160       --message-format FMT
161           The output format for diagnostic messages. Valid values:
162
163           ·   human (default): Display in a human-readable text format.
164
165           ·   json: Emit JSON messages to stdout.
166
167           ·   short: Emit shorter, human-readable text messages.
168
169       --build-plan
170           Outputs a series of JSON messages to stdout that indicate the
171           commands to run the build.
172
173           This option is unstable and available only on the nightly channel
174           <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
175           requires the -Z unstable-options flag to enable. See
176           https://github.com/rust-lang/cargo/issues/5579 for more
177           information.
178
179   Manifest Options
180       --manifest-path PATH
181           Path to the Cargo.toml file. By default, Cargo searches in the
182           current directory or any parent directory for the Cargo.toml file.
183
184       --frozen, --locked
185           Either of these flags requires that the Cargo.lock file is
186           up-to-date. If the lock file is missing, or it needs to be updated,
187           Cargo will exit with an error. The --frozen flag also prevents
188           Cargo from attempting to access the network to determine if it is
189           out-of-date.
190
191           These may be used in environments where you want to assert that the
192           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
193           network access.
194
195   Common Options
196       -h, --help
197           Prints help information.
198
199       -Z FLAG...
200           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
201           details.
202
203   Miscellaneous Options
204       -j N, --jobs N
205           Number of parallel jobs to run. May also be specified with the
206           build.jobs config value
207           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
208           to the number of CPUs.
209

PROFILES

211       Profiles may be used to configure compiler options such as optimization
212       levels and debug settings. See the reference
213       <https://doc.rust-lang.org/cargo/reference/manifest.html#the-profile-sections>
214       for more details.
215
216       Profile selection depends on the target and crate being built. By
217       default the dev or test profiles are used. If the --release flag is
218       given, then the release or bench profiles are used.
219
220       ┌────────────────────┬─────────────────┬───────────────────┐
221       │                    │                 │                   │
222       │Target              │ Default Profile │ --release Profile │
223       ├────────────────────┼─────────────────┼───────────────────┤
224       │                    │                 │                   │
225       │lib, bin, example   │ dev             release           
226       ├────────────────────┼─────────────────┼───────────────────┤
227       │                    │                 │                   │
228       │test, bench, or any │ test            bench             
229       │target              │                 │                   │
230       │in "test" or        │                 │                   │
231       │"bench" mode        │                 │                   │
232       └────────────────────┴─────────────────┴───────────────────┘
233
234       Dependencies use the dev/release profiles.
235

ENVIRONMENT

237       See the reference
238       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
239       for details on environment variables that Cargo reads.
240

EXIT STATUS

242       0
243           Cargo succeeded.
244
245       101
246           Cargo failed to complete.
247

EXAMPLES

249        1. Build the local package and all of its dependencies:
250
251               cargo build
252
253        2. Build with optimizations:
254
255               cargo build --release
256

SEE ALSO

258       cargo(1), cargo-rustc(1)
259
260
261
262                                  2019-03-28                    CARGO-BUILD(1)
Impressum