1CARGO-RUSTC(1) CARGO-RUSTC(1)
2
3
4
6 cargo-rustc - Compile the current package, and pass extra options to
7 the compiler
8
10 cargo rustc [OPTIONS] [-- ARGS]
11
13 The specified target for the current package (or package specified by
14 -p if provided) will be compiled along with all of its dependencies.
15 The specified ARGS will all be passed to the final compiler invocation,
16 not any of the dependencies. Note that the compiler will still
17 unconditionally receive arguments such as -L, --extern, and
18 --crate-type, and the specified ARGS will simply be added to the
19 compiler invocation.
20
21 See https://doc.rust-lang.org/rustc/index.html for documentation on
22 rustc flags.
23
24 This command requires that only one target is being compiled when
25 additional arguments are provided. If more than one target is available
26 for the current package the filters of --lib, --bin, etc, must be used
27 to select which target is compiled. To pass flags to all compiler
28 processes spawned by Cargo, use the RUSTFLAGS environment variable or
29 the build.rustflags config value
30 <https://doc.rust-lang.org/cargo/reference/config.html>.
31
33 Package Selection
34 By default, the package in the current working directory is selected.
35 The -p flag can be used to choose a different package in a workspace.
36
37 -p SPEC, --package SPEC
38 The package to build. See cargo-pkgid(1) for the SPEC format.
39
40 Target Selection
41 When no target selection options are given, cargo rustc will build all
42 binary and library targets of the selected package.
43
44 Passing target selection flags will build only the specified targets.
45
46 --lib
47 Build the package’s library.
48
49 --bin NAME...
50 Build the specified binary. This flag may be specified multiple
51 times.
52
53 --bins
54 Build all binary targets.
55
56 --example NAME...
57 Build the specified example. This flag may be specified multiple
58 times.
59
60 --examples
61 Build all example targets.
62
63 --test NAME...
64 Build the specified integration test. This flag may be specified
65 multiple times.
66
67 --tests
68 Build all targets in test mode that have the test = true manifest
69 flag set. By default this includes the library and binaries built
70 as unittests, and integration tests. Be aware that this will also
71 build any required dependencies, so the lib target may be built
72 twice (once as a unittest, and once as a dependency for binaries,
73 integration tests, etc.). Targets may be enabled or disabled by
74 setting the test flag in the manifest settings for the target.
75
76 --bench NAME...
77 Build the specified benchmark. This flag may be specified multiple
78 times.
79
80 --benches
81 Build all targets in benchmark mode that have the bench = true
82 manifest flag set. By default this includes the library and
83 binaries built as benchmarks, and bench targets. Be aware that this
84 will also build any required dependencies, so the lib target may be
85 built twice (once as a benchmark, and once as a dependency for
86 binaries, benchmarks, etc.). Targets may be enabled or disabled by
87 setting the bench flag in the manifest settings for the target.
88
89 --all-targets
90 Build all targets. This is equivalent to specifying --lib --bins
91 --tests --benches --examples.
92
93 Feature Selection
94 When no feature options are given, the default feature is activated for
95 every selected package.
96
97 --features FEATURES
98 Space or comma separated list of features to activate. These
99 features only apply to the current directory’s package. Features of
100 direct dependencies may be enabled with <dep-name>/<feature-name>
101 syntax.
102
103 --all-features
104 Activate all available features of all selected packages.
105
106 --no-default-features
107 Do not activate the default feature of the current directory’s
108 package.
109
110 Compilation Options
111 --target TRIPLE
112 Build for the given architecture. The default is the host
113 architecture. The general format of the triple is
114 <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
115 a list of supported targets.
116
117 This may also be specified with the build.target config value
118 <https://doc.rust-lang.org/cargo/reference/config.html>.
119
120 --release
121 Build optimized artifacts with the release profile. See the
122 PROFILES section for details on how this affects profile selection.
123
124 Output Options
125 --target-dir DIRECTORY
126 Directory for all generated artifacts and intermediate files. May
127 also be specified with the CARGO_TARGET_DIR environment variable,
128 or the build.target-dir config value
129 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
130 to target in the root of the workspace.
131
132 Display Options
133 -v, --verbose
134 Use verbose output. May be specified twice for "very verbose"
135 output which includes extra output such as dependency warnings and
136 build script output. May also be specified with the term.verbose
137 config value
138 <https://doc.rust-lang.org/cargo/reference/config.html>.
139
140 -q, --quiet
141 No output printed to stdout.
142
143 --color WHEN
144 Control when colored output is used. Valid values:
145
146 · auto (default): Automatically detect if color support is
147 available on the terminal.
148
149 · always: Always display colors.
150
151 · never: Never display colors.
152
153 May also be specified with the term.color config value
154 <https://doc.rust-lang.org/cargo/reference/config.html>.
155
156 --message-format FMT
157 The output format for diagnostic messages. Can be specified
158 multiple times and consists of comma-separated values. Valid
159 values:
160
161 · human (default): Display in a human-readable text format.
162
163 · short: Emit shorter, human-readable text messages.
164
165 · json: Emit JSON messages to stdout.
166
167 · json-diagnostic-short: Ensure the rendered field of JSON
168 messages contains the "short" rendering from rustc.
169
170 · json-diagnostic-rendered-ansi: Ensure the rendered field of
171 JSON messages contains embedded ANSI color codes for respecting
172 rustc’s default color scheme.
173
174 · json-render-diagnostics: Instruct Cargo to not include rustc
175 diagnostics in in JSON messages printed, but instead Cargo
176 itself should render the JSON diagnostics coming from rustc.
177 Cargo’s own JSON diagnostics and others coming from rustc are
178 still emitted.
179
180 Manifest Options
181 --manifest-path PATH
182 Path to the Cargo.toml file. By default, Cargo searches in the
183 current directory or any parent directory for the Cargo.toml file.
184
185 --frozen, --locked
186 Either of these flags requires that the Cargo.lock file is
187 up-to-date. If the lock file is missing, or it needs to be updated,
188 Cargo will exit with an error. The --frozen flag also prevents
189 Cargo from attempting to access the network to determine if it is
190 out-of-date.
191
192 These may be used in environments where you want to assert that the
193 Cargo.lock file is up-to-date (such as a CI build) or want to avoid
194 network access.
195
196 --offline
197 Prevents Cargo from accessing the network for any reason. Without
198 this flag, Cargo will stop with an error if it needs to access the
199 network and the network is not available. With this flag, Cargo
200 will attempt to proceed without the network if possible.
201
202 Beware that this may result in different dependency resolution than
203 online mode. Cargo will restrict itself to crates that are
204 downloaded locally, even if there might be a newer version as
205 indicated in the local copy of the index. See the cargo-fetch(1)
206 command to download dependencies before going offline.
207
208 May also be specified with the net.offline config value
209 <https://doc.rust-lang.org/cargo/reference/config.html>.
210
211 Common Options
212 -h, --help
213 Prints help information.
214
215 -Z FLAG...
216 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
217 details.
218
219 Miscellaneous Options
220 -j N, --jobs N
221 Number of parallel jobs to run. May also be specified with the
222 build.jobs config value
223 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
224 to the number of CPUs.
225
227 Profiles may be used to configure compiler options such as optimization
228 levels and debug settings. See the reference
229 <https://doc.rust-lang.org/cargo/reference/manifest.html#the-profile-sections>
230 for more details.
231
232 Profile selection depends on the target and crate being built. By
233 default the dev or test profiles are used. If the --release flag is
234 given, then the release or bench profiles are used.
235
236 ┌────────────────────┬─────────────────┬───────────────────┐
237 │ │ │ │
238 │Target │ Default Profile │ --release Profile │
239 ├────────────────────┼─────────────────┼───────────────────┤
240 │ │ │ │
241 │lib, bin, example │ dev │ release │
242 ├────────────────────┼─────────────────┼───────────────────┤
243 │ │ │ │
244 │test, bench, or any │ test │ bench │
245 │target │ │ │
246 │in "test" or │ │ │
247 │"bench" mode │ │ │
248 └────────────────────┴─────────────────┴───────────────────┘
249
250 Dependencies use the dev/release profiles.
251
253 See the reference
254 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
255 for details on environment variables that Cargo reads.
256
258 0
259 Cargo succeeded.
260
261 101
262 Cargo failed to complete.
263
265 1. Check if your package (not including dependencies) uses unsafe
266 code:
267
268 cargo rustc --lib -- -D unsafe-code
269
270 2. Try an experimental flag on the nightly compiler, such as this
271 which prints the size of every type:
272
273 cargo rustc --lib -- -Z print-type-sizes
274
276 cargo(1), cargo-build(1), rustc(1)
277
278
279
280 2019-06-07 CARGO-RUSTC(1)