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

OPTIONS

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. Valid values:
158
159           ·   human (default): Display in a human-readable text format.
160
161           ·   json: Emit JSON messages to stdout.
162
163           ·   short: Emit shorter, human-readable text messages.
164
165   Manifest Options
166       --manifest-path PATH
167           Path to the Cargo.toml file. By default, Cargo searches in the
168           current directory or any parent directory for the Cargo.toml file.
169
170       --frozen, --locked
171           Either of these flags requires that the Cargo.lock file is
172           up-to-date. If the lock file is missing, or it needs to be updated,
173           Cargo will exit with an error. The --frozen flag also prevents
174           Cargo from attempting to access the network to determine if it is
175           out-of-date.
176
177           These may be used in environments where you want to assert that the
178           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
179           network access.
180
181   Common Options
182       -h, --help
183           Prints help information.
184
185       -Z FLAG...
186           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
187           details.
188
189   Miscellaneous Options
190       -j N, --jobs N
191           Number of parallel jobs to run. May also be specified with the
192           build.jobs config value
193           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
194           to the number of CPUs.
195

PROFILES

197       Profiles may be used to configure compiler options such as optimization
198       levels and debug settings. See the reference
199       <https://doc.rust-lang.org/cargo/reference/manifest.html#the-profile-sections>
200       for more details.
201
202       Profile selection depends on the target and crate being built. By
203       default the dev or test profiles are used. If the --release flag is
204       given, then the release or bench profiles are used.
205
206       ┌────────────────────┬─────────────────┬───────────────────┐
207       │                    │                 │                   │
208       │Target              │ Default Profile │ --release Profile │
209       ├────────────────────┼─────────────────┼───────────────────┤
210       │                    │                 │                   │
211       │lib, bin, example   │ dev             release           
212       ├────────────────────┼─────────────────┼───────────────────┤
213       │                    │                 │                   │
214       │test, bench, or any │ test            bench             
215       │target              │                 │                   │
216       │in "test" or        │                 │                   │
217       │"bench" mode        │                 │                   │
218       └────────────────────┴─────────────────┴───────────────────┘
219
220       Dependencies use the dev/release profiles.
221

ENVIRONMENT

223       See the reference
224       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
225       for details on environment variables that Cargo reads.
226

EXIT STATUS

228       0
229           Cargo succeeded.
230
231       101
232           Cargo failed to complete.
233

EXAMPLES

235        1. Check if your package (not including dependencies) uses unsafe
236           code:
237
238               cargo rustc --lib -- -D unsafe-code
239
240        2. Try an experimental flag on the nightly compiler, such as this
241           which prints the size of every type:
242
243               cargo rustc --lib -- -Z print-type-sizes
244

SEE ALSO

246       cargo(1), cargo-build(1), rustc(1)
247
248
249
250                                  2018-12-20                    CARGO-RUSTC(1)
Impressum