1RUSTC(1) User Commands RUSTC(1)
2
3
4
6 rustc - The Rust compiler
7
9 rustc [OPTIONS] INPUT
10
11
13 This program is a compiler for the Rust language, available at
14 https://www.rust-lang.org.
15
16
18 -h, --help
19 Display the help message.
20
21 --cfg SPEC
22 Configure the compilation environment.
23
24 -L [KIND=]PATH
25 Add a directory to the library search path. The optional KIND
26 can be one of:
27
28 dependency
29 only lookup transitive dependencies here
30
31 crate only lookup local `extern crate` directives here
32
33 native only lookup native libraries here
34
35 framework
36 only look for OSX frameworks here
37
38 all look for anything here (the default)
39
40 -l [KIND=]NAME
41 Link the generated crate(s) to the specified library NAME. The
42 optional KIND can be one of static, dylib, or framework. If
43 omitted, dylib is assumed.
44
45 --crate-type [bin|lib|rlib|dylib|cdylib|staticlib]
46 Comma separated list of types of crates for the compiler to
47 emit.
48
49 --crate-name NAME
50 Specify the name of the crate being built.
51
52 --emit [asm|llvm-bc|llvm-ir|obj|link|dep-info|mir][=PATH]
53 Configure the output that rustc will produce. Each emission may
54 also have an optional explicit output PATH specified for that
55 particular emission kind. This path takes precedence over the -o
56 option.
57
58 --print [crate-name|file-names|sysroot|cfg|target-list|target-cpus|tar‐
59 get-features|relocation-models|code-models|tls-models|target-spec-json|
60 native-static-libs]
61 Comma separated list of compiler information to print on stdout.
62
63 -g Equivalent to -C debuginfo=2.
64
65 -O Equivalent to -C opt-level=2.
66
67 -o FILENAME
68 Write output to FILENAME. Ignored if multiple --emit outputs are
69 specified which don't have an explicit path otherwise.
70
71 --out-dir DIR
72 Write output to compiler‐chosen filename in DIR. Ignored if -o
73 is specified. Defaults to the current directory.
74
75 --explain OPT
76 Provide a detailed explanation of an error message.
77
78 --test Build a test harness.
79
80 --target TARGET
81 Target triple for which the code is compiled. This option
82 defaults to the host’s target triple. The target triple has the
83 general format <arch><sub>-<vendor>-<sys>-<abi>, where:
84
85 <arch> x86, arm, thumb, mips, etc.
86
87 <sub> for example on ARM: v5, v6m, v7a, v7m, etc.
88
89 <vendor>
90 pc, apple, nvidia, ibm, etc.
91
92 <sys> none, linux, win32, darwin, cuda, etc.
93
94 <abi> eabi, gnu, android, macho, elf, etc.
95
96 -W help
97 Print 'lint' options and default settings.
98
99 -W OPT, --warn OPT
100 Set lint warnings.
101
102 -A OPT, --allow OPT
103 Set lint allowed.
104
105 -D OPT, --deny OPT
106 Set lint denied.
107
108 -F OPT, --forbid OPT
109 Set lint forbidden.
110
111 -C FLAG[=VAL], --codegen FLAG[=VAL]
112 Set a codegen‐related flag to the value specified. Use -C help
113 to print available flags. See CODEGEN OPTIONS below.
114
115 -V, --version
116 Print version info and exit.
117
118 -v, --verbose
119 Use verbose output.
120
121 --remap-path-prefix from=to
122 Remap source path prefixes in all output, including compiler
123 diagnostics, debug information, macro expansions, etc. The
124 from=to parameter is scanned from right to left, so from may
125 contain '=', but to may not.
126
127 This is useful for normalizing build products, for example by
128 removing the current directory out of pathnames emitted into the
129 object files. The replacement is purely textual, with no consid‐
130 eration of the current system's pathname syntax. For example
131 --remap-path-prefix foo=bar will match foo/lib.rs but not
132 ./foo/lib.rs.
133
134 --extern NAME=PATH
135 Specify where an external rust library is located. These should
136 match extern declarations in the crate's source code.
137
138 --sysroot PATH
139 Override the system root.
140
141 -Z FLAG
142 Set internal debugging options. Use -Z help to print available
143 options.
144
145 --color auto|always|never
146 Configure coloring of output:
147
148 auto colorize, if output goes to a tty (default);
149
150 always always colorize output;
151
152 never never colorize output.
153
154
156 linker=/path/to/cc
157 Path to the linker utility to use when linking libraries, exe‐
158 cutables, and objects.
159
160 link-args='-flag1 -flag2'
161 A space‐separated list of extra arguments to pass to the linker
162 when the linker is invoked.
163
164 lto Perform LLVM link‐time optimizations.
165
166 target-cpu=help
167 Selects a target processor. If the value is 'help', then a list
168 of available CPUs is printed.
169
170 target-feature='+feature1,-feature2'
171 A comma‐separated list of features to enable or disable for the
172 target. A preceding '+' enables a feature while a preceding '-'
173 disables it. Available features can be discovered through llc
174 -mcpu=help.
175
176 passes=val
177 A space‐separated list of extra LLVM passes to run. A value of
178 'list' will cause rustc to print all known passes and exit. The
179 passes specified are appended at the end of the normal pass man‐
180 ager.
181
182 llvm-args='-arg1 -arg2'
183 A space‐separated list of arguments to pass through to LLVM.
184
185 save-temps
186 If specified, the compiler will save more files (.bc, .o,
187 .no-opt.bc) generated throughout compilation in the output
188 directory.
189
190 rpath If specified, then the rpath value for dynamic libraries will be
191 set in either dynamic library or executable outputs.
192
193 no-prepopulate-passes
194 Suppresses pre‐population of the LLVM pass manager that is run
195 over the module.
196
197 no-vectorize-loops
198 Suppresses running the loop vectorization LLVM pass, regardless
199 of optimization level.
200
201 no-vectorize-slp
202 Suppresses running the LLVM SLP vectorization pass, regardless
203 of optimization level.
204
205 soft-float
206 Generates software floating point library calls instead of hard‐
207 ware instructions.
208
209 prefer-dynamic
210 Prefers dynamic linking to static linking.
211
212 no-integrated-as
213 Force usage of an external assembler rather than LLVM's inte‐
214 grated one.
215
216 no-redzone
217 Disable the use of the redzone.
218
219 relocation-model=[pic,static,dynamic-no-pic]
220 The relocation model to use. (Default: pic)
221
222 code-model=[small,kernel,medium,large]
223 Choose the code model to use.
224
225 metadata=val
226 Metadata to mangle symbol names with.
227
228 extra-filename=val
229 Extra data to put in each output filename.
230
231 codegen-units=n
232 Divide crate into n units to optimize in parallel.
233
234 remark=val
235 Print remarks for these optimization passes (space separated, or
236 "all").
237
238 no-stack-check
239 Disable checks for stack exhaustion (a memory‐safety hazard!).
240
241 debuginfo=val
242 Debug info emission level:
243
244 0 no debug info;
245
246 1 line‐tables only (for stacktraces and breakpoints);
247
248 2 full debug info with variable and type information.
249
250 opt-level=VAL
251 Optimize with possible levels 0–3, s (optimize for size), or z
252 (for minimal size)
253
254
256 Some of these affect only test harness programs (generated via rustc
257 --test); others affect all programs which link to the Rust standard
258 library.
259
260
261 RUST_TEST_THREADS
262 The test framework Rust provides executes tests in parallel.
263 This variable sets the maximum number of threads used for this
264 purpose. This setting is overridden by the --test-threads
265 option.
266
267
268 RUST_TEST_NOCAPTURE
269 If set to a value other than "0", a synonym for the --nocapture
270 flag.
271
272
273 RUST_MIN_STACK
274 Sets the minimum stack size for new threads.
275
276
277 RUST_BACKTRACE
278 If set to a value different than "0", produces a backtrace in
279 the output of a program which panics.
280
281
283 To build an executable from a source file with a main function:
284 $ rustc -o hello hello.rs
285
286 To build a library from a source file:
287 $ rustc --crate-type=lib hello-lib.rs
288
289 To build either with a crate (.rs) file:
290 $ rustc hello.rs
291
292 To build an executable with debug info:
293 $ rustc -g -o hello hello.rs
294
295
297 rustdoc(1)
298
299
301 See https://github.com/rust-lang/rust/issues for issues.
302
303
305 See https://github.com/rust-lang/rust/graphs/contributors or use `git
306 log --all --format='%cN <%cE>' | sort -u` in the rust source distribu‐
307 tion.
308
309
311 This work is dual‐licensed under Apache 2.0 and MIT terms. See COPY‐
312 RIGHT file in the rust source distribution.
313
314
315
316rustc 1.43.0 April 2020 RUSTC(1)