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