RUSTC(1)

πŸ“¦ version 1.95.0, in ubuntu stonking

πŸ’– NAME πŸ’–

rustc β€” The Rust compiler. yes bestie, THE compiler, the one that turns your .rs files into things that actually run. main character energy.


πŸ¦‹ SYNOPSIS πŸ¦‹

rustc [OPTIONS] INPUT

✨ DESCRIPTION ✨

this program is a compiler for the Rust language 🌈 and it lives at https://www.rust-lang.org. that's the whole vibe. it reads your code, it thinks about your code, it produces your code. iconic behavior honestly.


πŸ‘‘ OPTIONS πŸ‘‘

  • -h, --help β€” shows you the help message. the classic "help me help you" move 🫢
  • --cfg SPEC β€” configures the compilation environment. set the mood for your build πŸ’…
  • -L [KIND=]PATH β€” adds a directory to the library search path. the KIND part is optional and can be one of these lil guys:
    • dependency β€” only lookup transitive dependencies here
    • crate β€” only lookup local extern crate directives here
    • native β€” only lookup native libraries here
    • framework β€” only look for OSX frameworks here
    • all β€” look for anything here (this is the default)
  • -l [KIND=]NAME β€” links the generated crate(s) to the library NAME you picked. the optional KIND can be static, dylib, or framework. if you don't say anything, dylib is assumed. no cap.
  • --crate-type [bin|lib|rlib|dylib|cdylib|staticlib|proc-macro] β€” a comma separated list of types of crates for the compiler to emit. pick your fighter ⭐
  • --crate-name NAME β€” specifies the name of the crate being built. name her, she deserves it πŸŽ€
  • --emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir][=PATH] β€” configures the output that rustc will produce. each emission may also have an optional explicit output PATH specified for that particular emission kind. this path takes precedence over the -o option, so pay attention bestie πŸ‘€
  • --print [crate-name|file-names|sysroot|target-libdir|cfg|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|native-static-libs|stack-protector-strategies|link-args] β€” a comma separated list of compiler information to print on stdout. it's giving "tell me everything" πŸ”₯
  • -g β€” equivalent to -C debuginfo=2.
  • -O β€” equivalent to -C opt-level=2. speed ✨
  • -o FILENAME β€” writes output to FILENAME. it's ignored if multiple --emit outputs are specified which don't have an explicit path otherwise. rude but true πŸ’€
  • --out-dir DIR β€” writes output to a compiler‐chosen filename in DIR. ignored if -o is specified. defaults to the current directory.
  • --explain OPT β€” provides a detailed explanation of an error message. like a little tutor, we love her πŸ“š
  • --test β€” builds a test harness.
  • --target TARGET β€” the target tuple for which the code is compiled. this option defaults to the host's target tuple. the target tuple has the general format <arch><sub>-<vendor>-<sys>-<abi>, where:
    • <arch> β€” x86, arm, thumb, mips, etc.
    • <sub> β€” for example on ARM: v5, v6m, v7a, v7m, etc.
    • <vendor> β€” pc, apple, nvidia, ibm, etc.
    • <sys> β€” none, linux, win32, darwin, cuda, etc.
    • <abi> β€” eabi, gnu, android, macho, elf, etc.
  • -W help β€” prints 'lint' options and default settings.
  • -W OPT, --warn OPT β€” sets lint warnings.
  • -A OPT, --allow OPT β€” sets lint allowed.
  • -D OPT, --deny OPT β€” sets lint denied.
  • -F OPT, --forbid OPT β€” sets lint forbidden. yeah she's strict like that 😀
  • -C FLAG[=VAL], --codegen FLAG[=VAL] β€” sets a codegen‐related flag to the value specified. use -C help to print available flags. see CODEGEN OPTIONS below, bestie ⬇️
  • -V, --version β€” prints version info and exits. hi, byeee πŸ‘‹
  • -v, --verbose β€” use verbose output. say more words, we love words πŸ’¬
  • --remap-path-prefix from=to β€” remaps source path prefixes in all output, including compiler diagnostics, debug information, macro expansions, etc. the from=to parameter is scanned from right to left, so from may contain '=', but to may not.

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 ./foo/lib.rs. yes, that distinction matters, don't come for me πŸ™ˆ

  • --extern NAME=PATH β€” specifies where an external rust library is located. these should match extern declarations in the crate's source code.
  • --sysroot PATH β€” overrides the system root.
  • -Z FLAG β€” sets unstable / perma-unstable options. use -Z help to print available options. 🚨 these are the wild ones, tread carefully 🚨
  • --color auto|always|never β€” configures coloring of output:
    • auto β€” colorize, if output goes to a tty (default);
    • always β€” always colorize output;
    • never β€” never colorize output.

🧚 CODEGEN OPTIONS 🧚

  • linker=/path/to/cc β€” path to the linker utility to use when linking libraries, executables, and objects.
  • link-args='-flag1 -flag2' β€” a space‐separated list of extra arguments to pass to the linker when the linker is invoked.
  • lto β€” perform LLVM link‐time optimizations.
  • target-cpu=help β€” selects a target processor. if the value is 'help', then a list of available CPUs is printed.
  • target-feature='+feature1,-feature2' β€” a comma‐separated list of features to enable or disable for the target. a preceding '+' enables a feature while a preceding '-' disables it. available features can be discovered through llc -mcpu=help.
  • passes=val β€” a space‐separated list of extra LLVM passes to run. a value of 'list' will cause rustc to print all known passes and exit. the passes specified are appended at the end of the normal pass manager.
  • llvm-args='-arg1 -arg2' β€” a space‐separated list of arguments to pass through to LLVM.
  • save-temps β€” if specified, the compiler will save more files (.bc, .o, .no-opt.bc) generated throughout compilation in the output directory.
  • rpath β€” if specified, then the rpath value for dynamic libraries will be set in either dynamic library or executable outputs.
  • no-prepopulate-passes β€” suppresses pre‐population of the LLVM pass manager that is run over the module.
  • no-vectorize-loops β€” suppresses running the loop vectorization LLVM pass, regardless of optimization level.
  • no-vectorize-slp β€” suppresses running the LLVM SLP vectorization pass, regardless of optimization level.
  • soft-float β€” generates software floating point library calls instead of hardware instructions.
  • prefer-dynamic β€” prefers dynamic linking to static linking.
  • no-integrated-as β€” force usage of an external assembler rather than LLVM's integrated one.
  • no-redzone β€” disable the use of the redzone.
  • relocation-model=[pic,static,dynamic-no-pic] β€” the relocation model to use. (Default: pic)
  • code-model=[small,kernel,medium,large] β€” choose the code model to use.
  • metadata=val β€” metadata to mangle symbol names with.
  • extra-filename=val β€” extra data to put in each output filename.
  • codegen-units=n β€” divide crate into n units to optimize in parallel. parallelism slay πŸ’…
  • remark=val β€” print remarks for these optimization passes (space separated, or "all").
  • no-stack-check β€” disable checks for stack exhaustion (a memory‐safety hazard!) 😭 please be careful
  • debuginfo=val β€” debug info emission level:
    • 0 β€” no debug info;
    • 1 β€” line‐tables only (for stacktraces and breakpoints);
    • 2 β€” full debug info with variable and type information.
  • opt-level=VAL β€” optimize with possible levels 0–3, s (optimize for size), or z (for minimal size).

🌈 ENVIRONMENT 🌈

some of these affect only test harness programs (generated via rustc --test); others affect all programs which link to the Rust standard library. okay so:

  • RUST_TEST_THREADS β€” the test framework Rust provides executes tests in parallel. this variable sets the maximum number of threads used for this purpose. this setting is overridden by the --test-threads option.
  • RUST_TEST_NOCAPTURE β€” if set to a value other than "0", a synonym for the --nocapture flag.
  • RUST_MIN_STACK β€” sets the minimum stack size for new threads.
  • RUST_BACKTRACE β€” if set to a value different than "0", produces a backtrace in the output of a program which panics. very "tell me what went wrong bestie" 🫢

πŸ“ EXAMPLES πŸ“

to build an executable from a source file with a main function:

$ rustc -o hello hello.rs

to build a library from a source file:

$ rustc --crate-type=lib hello-lib.rs

to build either with a crate (.rs) file:

$ rustc hello.rs

to build an executable with debug info:

$ rustc -g -o hello hello.rs

πŸ’œ SEE ALSO πŸ’œ

rustdoc(1) β€” her sister, also iconic.


πŸ’€ BUGS πŸ’€

see https://github.com/rust-lang/rust/issues for issues. if you found one, you're lowkey a contributor now, congrats.


πŸŽ€ AUTHOR πŸŽ€

see https://github.com/rust-lang/rust/graphs/contributors β€” or use this in the rust source distribution:

git log --all --format='%cN <%cE>' | sort -u

it's giving detective work fr fr πŸ”


this work is dual‐licensed under Apache 2.0 and MIT terms. see the COPYRIGHT file in the rust source distribution.


okay that's the whole page bestie, you're officially a rustc girlie now πŸ¦‹πŸ’– this was rustc, manual page version <INSERT VERSION HERE>, dated April 2019 β€” and yes, the manual name lives up top where it belongs. periodt. πŸ‘‘βœ¨

πŸ“¦ where this page comes from