1CARGO-RUSTC(1)                                                  CARGO-RUSTC(1)
2
3
4

NAME

6       cargo-rustc - Compile the current package, and pass extra options to
7       the compiler
8

SYNOPSIS

10       cargo rustc [OPTIONS] [-- ARGS]
11

DESCRIPTION

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
29       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
30       or the build.rustflags config value
31       <https://doc.rust-lang.org/cargo/reference/config.html>.
32

OPTIONS

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

PROFILES

243       Profiles may be used to configure compiler options such as optimization
244       levels and debug settings. See the reference
245       <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
246       details.
247
248       Profile selection depends on the target and crate being built. By
249       default the dev or test profiles are used. If the --release flag is
250       given, then the release or bench profiles are used.
251
252       ┌────────────────────┬─────────────────┬───────────────────┐
253       │                    │                 │                   │
254       │Target              │ Default Profile │ --release Profile │
255       ├────────────────────┼─────────────────┼───────────────────┤
256       │                    │                 │                   │
257       │lib, bin, example   │ dev             release           
258       ├────────────────────┼─────────────────┼───────────────────┤
259       │                    │                 │                   │
260       │test, bench, or any │ test            bench             
261       │target              │                 │                   │
262       │in "test" or        │                 │                   │
263       │"bench" mode        │                 │                   │
264       └────────────────────┴─────────────────┴───────────────────┘
265
266       Dependencies use the dev/release profiles.
267

ENVIRONMENT

269       See the reference
270       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
271       for details on environment variables that Cargo reads.
272

EXIT STATUS

274       0
275           Cargo succeeded.
276
277       101
278           Cargo failed to complete.
279

EXAMPLES

281        1. Check if your package (not including dependencies) uses unsafe
282           code:
283
284               cargo rustc --lib -- -D unsafe-code
285
286        2. Try an experimental flag on the nightly compiler, such as this
287           which prints the size of every type:
288
289               cargo rustc --lib -- -Z print-type-sizes
290

SEE ALSO

292       cargo(1), cargo-build(1), rustc(1)
293
294
295
296                                  2020-02-06                    CARGO-RUSTC(1)
Impressum