Here's a list of command-line arguments to
rustc and what they do.
This flag will print out help information for
This flag can turn on or off various
#[cfg] settings for conditional
The value can either be a single identifier or two identifiers separated by
--cfg 'verbose' or
--cfg 'feature="serde"'. These correspond
#[cfg(feature = "serde")] respectively.
-L flag adds a path to search for external crates and libraries.
The kind of search path can optionally be specified with the form
-L KIND=PATH where
KIND may be one of:
dependency— Only search for transitive dependencies in this directory.
crate— Only search for this crate's direct dependencies in this directory.
native— Only search for native libraries in this directory.
framework— Only search for macOS frameworks in this directory.
all— Search for all library kinds in this directory. This is the default if
KINDis not specified.
This flag allows you to specify linking to a specific native library when building a crate.
The kind of library can optionally be specified with the form
KIND may be one of:
dylib— A native dynamic library.
static— A native static library (such as a
framework— A macOS framework.
The kind of library can be specified in a
attribute. If the kind is not specified in the
attribute or on the command-line, it will link a dynamic library if available,
otherwise it will use a static library. If the kind is specified on the
command-line, it will override the kind specified in a
The name used in a
link attribute may be overridden using the form
-l ATTR_NAME:LINK_NAME where
ATTR_NAME is the name in the
LINK_NAME is the name of the actual library that will be linked.
rustc on which crate type to build. This flag accepts a
comma-separated list of values, and may be specified multiple times. The valid
crate types are:
lib— Generates a library kind preferred by the compiler, currently defaults to
rlib— A Rust static library.
staticlib— A native static library.
dylib— A Rust dynamic library.
cdylib— A native dynamic library.
bin— A runnable executable program.
proc-macro— Generates a format suitable for a procedural macro library that may be loaded by the compiler.
The crate type may be specified with the
--crate-type command-line value will override the
More details may be found in the linkage chapter of the reference.
rustc of the name of your crate.
This flag takes a value of
2018. The default is
information about editions may be found in the edition guide.
This flag controls the types of output files generated by the compiler. It accepts a comma-separated list of values, and may be specified multiple times. The valid emit kinds are:
asm— Generates a file with the crate's assembly code. The default output filename is
dep-info— Generates a file with Makefile syntax that indicates all the source files that were loaded to generate the crate. The default output filename is
link— Generates the crates specified by
--crate-type. The default output filenames depend on the crate type and platform. This is the default if
--emitis not specified.
llvm-bc— Generates a binary file containing the LLVM bitcode. The default output filename is
llvm-ir— Generates a file containing LLVM IR. The default output filename is
metadata— Generates a file containing metadata about the crate. The default output filename is
mir— Generates a file containing rustc's mid-level intermediate representation. The default output filename is
obj— Generates a native object file. The default output filename is
The output filename can be set with the
-o flag. A
suffix may be added to the filename with the
flag. The files are written to the
current directory unless the
--out-dir flag is used. Each
emission type may also specify the output filename with the form
which takes precedence over the
This flag prints out various information about the compiler. This flag may be
specified multiple times, and the information is printed in the order the
flags are specified. Specifying a
--emit step and will only print the requested information.
The valid types of print values are:
crate-name— The name of the crate.
file-names— The names of the files created by the
sysroot— Path to the sysroot.
cfg— List of cfg values. See conditional compilation for more information about cfg values.
target-list— List of known targets. The target may be selected with the
target-cpus— List of available CPU values for the current target. The target CPU may be selected with the
target-features— List of available target features for the current target. Target features may be enabled with the
-C target-feature=valflag. This flag is unsafe. See known issues for more details.
relocation-models— List of relocation models. Relocation models may be selected with the
code-models— List of code models. Code models may be selected with the
tls-models— List of Thread Local Storage models supported. The model may be selected with the
native-static-libs— This may be used when creating a
staticlibcrate type. If this is the only flag, it will perform a full compilation and include a diagnostic note that indicates the linker flags to use when linking the resulting static library. The note starts with the text
native-static-libs:to make it easier to fetch the output.
A synonym for
A synonym for
This flag controls the output filename.
The outputted crate will be written to this directory. This flag is ignored if
-o flag is used.
Each error of
rustc's comes with an error code; this will print
out a longer explanation of a given error.
When compiling this crate,
rustc will ignore your
and instead produce a test harness.
This controls which target to produce.
This flag will set which lints should be set to the warn level.
This flag will set which lints should be set to the allow level.
This flag will set which lints should be set to the deny level.
This flag will set which lints should be set to the forbid level.
This flag will allow you to set unstable options of rustc. In order to set multiple options,
the -Z flag can be used multiple times. For example:
rustc -Z verbose -Z time.
Specifying options with -Z is only available on nightly. To view all available options
rustc -Z help.
This flag lets you 'cap' lints, for more, see here.
This flag will allow you to set codegen options.
This flag will print out
This flag, when combined with other flags, makes them produce extra output.
This flag allows you to pass the name and location for an external crate of a
direct dependency. Indirect dependencies (dependencies of dependencies) are
located using the
-L flag. The given crate name is
added to the extern prelude, which is the same as specifying
within the root module. The given crate name does not need to match the name
the library was built with.
This flag may be specified multiple times. This flag takes an argument with either of the following formats:
CRATENAME=PATH— Indicates the given crate is found at the given path.
CRATENAME— Indicates the given crate may be found in the search path, such as within the sysroot or via the
The same crate name may be specified multiple times for different crate types.
If both an
dylib are found, an internal algorithm is used to
decide which to use for linking. The
flag may be used to influence which is used.
If the same crate name is specified with and without a path, the one with the path is used and the pathless flag has no effect.
The "sysroot" is where
rustc looks for the crates that come with the Rust
distribution; this flag allows that to be overridden.
This flag lets you control the format of messages. Messages are printed to stderr. The valid options are:
human— Human-readable output. This is the default.
json— Structured JSON output. See the JSON chapter for more detail.
short— Short, one-line messages.
This flag lets you control color settings of the output. The valid options are:
auto— Use colors if output goes to a tty. This is the default.
always— Always use colors.
never— Never colorize output.
Remap source path prefixes in all output, including compiler diagnostics,
debug information, macro expansions, etc. It takes a value of the form
FROM=TO where a path prefix equal to
FROM is rewritten to the value
FROM may itself contain an
= symbol, but the
TO value may not. This
flag may be specified multiple times.
This is useful for normalizing build products, for example by removing the
current directory out of pathnames emitted into the object files. The
replacement is purely textual, with no consideration of the current system's
pathname syntax. For example
--remap-path-prefix foo=bar will match
foo/lib.rs but not
--error-format=json option is passed to
rustc then all of the compiler's diagnostic output will be emitted in the form
of JSON blobs. The
--json argument can be used in conjunction with
--error-format=json to configure what the JSON blobs contain as well as
which ones are emitted.
--error-format=json the compiler will always emit any compiler errors as
a JSON blob, but the following options are also available to the
to customize the output:
diagnostic-short- json blobs for diagnostic messages should use the "short" rendering instead of the normal "human" default. This means that the output of
--error-format=shortwill be embedded into the JSON diagnostics instead of the default
diagnostic-rendered-ansi- by default JSON blobs in their
renderedfield will contain a plain text rendering of the diagnostic. This option instead indicates that the diagnostic should have embedded ANSI color codes intended to be used to colorize the message in the manner rustc typically already does for terminal outputs. Note that this is usefully combined with crates like
fwdansito translate these ANSI codes on Windows to console commands or
strip-ansi-escapesif you'd like to optionally remove the ansi colors afterwards.
artifacts- this instructs rustc to emit a JSON blob for each artifact that is emitted. An artifact corresponds to a request from the
--emitCLI argument, and as soon as the artifact is available on the filesystem a notification will be emitted.
Note that it is invalid to combine the
--json argument with the
--color argument, and it is required to combine
See the JSON chapter for more detail.
If you specify
@path on the command-line, then it will open
path and read
command line options from it. These options are one per line; a blank line indicates
an empty option. The file can use Unix or Windows style line endings, and must be
encoded as UTF-8.