1 # Command-line arguments
3 Here's a list of command-line arguments to `rustc` and what they do.
5 ## `-h`/`--help`: get help
7 This flag will print out help information for `rustc`.
9 ## `--cfg`: configure the compilation environment
11 This flag can turn on or off various `#[cfg]` settings.
13 The value can either be a single identifier or two identifiers separated by `=`.
15 For examples, `--cfg 'verbose'` or `--cfg 'feature="serde"'`. These correspond
16 to `#[cfg(verbose)]` and `#[cfg(feature = "serde")]` respectively.
18 ## `-L`: add a directory to the library search path
20 When looking for external crates, a directory passed to this flag will be searched.
22 ## `-l`: link the generated crate to a native library
24 This flag allows you to specify linking to a specific native library when building
27 ## `--crate-type`: a list of types of crates for the compiler to emit
29 This instructs `rustc` on which crate type to build.
31 ## `--crate-name`: specify the name of the crate being built
33 This informs `rustc` of the name of your crate.
35 ## `--emit`: emit output other than a crate
37 Instead of producing a crate, this flag can print out things like the assembly or LLVM-IR.
39 ## `--print`: print compiler information
41 This flag prints out various information about the compiler.
43 ## `-g`: include debug information
45 A synonym for `-C debuginfo=2`, for more see [here](codegen-options/index.html#debuginfo).
47 ## `-O`: optimize your code
49 A synonym for `-C opt-level=2`, for more see [here](codegen-options/index.html#opt-level).
51 ## `-o`: filename of the output
53 This flag controls the output filename.
55 ## `--out-dir`: directory to write the output in
57 The outputted crate will be written to this directory.
59 ## `--explain`: provide a detailed explanation of an error message
61 Each error of `rustc`'s comes with an error code; this will print
62 out a longer explanation of a given error.
64 ## `--test`: build a test harness
66 When compiling this crate, `rustc` will ignore your `main` function
67 and instead produce a test harness.
69 ## `--target`: select a target triple to build
71 This controls which [target](targets/index.html) to produce.
73 ## `-W`: set lint warnings
75 This flag will set which lints should be set to the [warn level](lints/levels.html#warn).
77 ## `-A`: set lint allowed
79 This flag will set which lints should be set to the [allow level](lints/levels.html#allow).
81 ## `-D`: set lint denied
83 This flag will set which lints should be set to the [deny level](lints/levels.html#deny).
85 ## `-F`: set lint forbidden
87 This flag will set which lints should be set to the [forbid level](lints/levels.html#forbid).
89 ## `-Z`: set unstable options
91 This flag will allow you to set unstable options of rustc. In order to set multiple options,
92 the -Z flag can be used multiple times. For example: `rustc -Z verbose -Z time`.
93 Specifying options with -Z is only available on nightly. To view all available options
96 ## `--cap-lints`: set the most restrictive lint level
98 This flag lets you 'cap' lints, for more, [see here](lints/levels.html#capping-lints).
100 ## `-C`/`--codegen`: code generation options
102 This flag will allow you to set [codegen options](codegen-options/index.html).
104 ## `-V`/`--version`: print a version
106 This flag will print out `rustc`'s version.
108 ## `-v`/`--verbose`: use verbose output
110 This flag, when combined with other flags, makes them produce extra output.
112 ## `--extern`: specify where an external library is located
114 This flag allows you to pass the name and location of an external crate that will
115 be linked into the crate you're buildling.
117 ## `--sysroot`: Override the system root
119 The "sysroot" is where `rustc` looks for the crates that come with the Rust
120 distribution; this flag allows that to be overridden.
122 ## `--error-format`: control how errors are produced
124 This flag lets you control the format of errors.
126 ## `--color`: configure coloring of output
128 This flag lets you control color settings of the output.