RUSTC(1)

πŸ“¦ version 1.97.1, in ubuntu stonking

✨ RUSTC(1) ✨

okay bestie, sit down, hydrate, because we're about to talk about rustc, which is the Rust compiler, and also lowkey the moment your .rs file stops being vibes and starts being a binary. this is the rustc(1) manual, User Commands edition, and yes i'm gonna walk you through every single flag like it's a group chat recap. no skips. no "we'll get to that later." we're doing all of it. πŸ’…


🌸 NAME 🌸

rustc β€” The Rust compiler. that's it. that's the name. iconic, honestly. πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

rustc [OPTIONS] INPUT

like… that's the whole thing. options, then the input file, go. slay.


πŸ’œ DESCRIPTION πŸ’œ

okay so this program is a compiler for the Rust language, and if you wanna find the language itself it lives at https://www.rust-lang.org. that's the whole description. short. mysterious. main character energy. 🫢


πŸŽ€ OPTIONS πŸŽ€

here's where it gets juicy. every flag, right here, no crumbs left behind.

  • -h, --help β€” shows you the help message. when in doubt, bestie, ask for help. πŸ™ˆ
  • --cfg SPEC β€” configure the compilation environment. you're setting the vibe of the build.
  • -L [KIND=]PATH β€” adds a directory to the library search path. the KIND part is optional, and when you use it, it can be exactly one of these:
    • 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 one's the default πŸ’–)
  • -l [KIND=]NAME β€” links the generated crate(s) to the library called NAME. KIND is optional and can be static, dylib, or framework. if you skip it entirely, dylib is assumed. not me reminding you about defaults 😭
  • --crate-type [bin|lib|rlib|dylib|cdylib|staticlib|proc-macro] β€” a comma separated list of the types of crates the compiler should emit. pick your fighter(s).
  • --crate-name NAME β€” tells the compiler what the crate being built is called. name it like you mean it.
  • --emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir][=PATH] β€” configures the output rustc will produce. each emission can also have its own optional explicit output PATH for that particular emission kind. heads up: that path takes precedence over the -o option. periodt. πŸ”₯
  • --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 info to print on stdout. it's giving "tell me everything about yourself" and honestly? respect. ⭐
  • -g β€” equivalent to -C debuginfo=2.
  • -O β€” equivalent to -C opt-level=2.
  • -o FILENAME β€” writes output to FILENAME. it gets ignored if multiple --emit outputs are specified which don't have an explicit path otherwise. read that twice, bestie, it matters. πŸ‘€
  • --out-dir DIR β€” writes output to a compiler-chosen filename inside DIR. ignored if -o is specified. defaults to the current directory.
  • --explain OPT β€” gives you a detailed explanation of an error message. like a translator for when the compiler yells at you πŸ₯Ί
  • --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 their default settings. a little lint menu. bon appΓ©tit πŸ“
  • -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. the final boss of lint levels πŸ’€
  • -C FLAG[=VAL], --codegen FLAG[=VAL] β€” sets a codegen-related flag to the value you specified. use -C help to print the available flags. and like… see CODEGEN OPTIONS below, because we're going there. (spoiler: it's a whole section) 🌈
  • -V, --version β€” prints version info and exits. the "who even am i" flag.
  • -v, --verbose β€” use verbose output. more words. more info. more everything. πŸ“’
  • --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. that last bit is a jump scare, bestie, write it down. 😭

  • --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 the available options. (iykyk 🧚)
  • --color auto|always|never β€” configures coloring of the output:
    • auto β€” colorize, if output goes to a tty (this is the default);
    • always β€” always colorize output;
    • never β€” never colorize output.

πŸ”₯ CODEGEN OPTIONS πŸ”₯

bestie these are the -C / --codegen flags and there are. so. many. every single one below, no cap.

  • 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 β€” performs 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. hoarder behavior, but make it compiling πŸŽ€
  • 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. it's giving "i don't trust the built-in one" πŸ’…
  • no-redzone β€” disables 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 β€” divides the crate into n units to optimize in parallel. multitasking icon πŸ’–
  • remark=val β€” print remarks for these optimization passes (space separated, or "all").
  • no-stack-check β€” disables checks for stack exhaustion. this one is a memory-safety hazard! a real one! not a cute one! be careful bestie 😭
  • debuginfo=val β€” the 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 β€” optimizes with possible levels 0–3, s (optimize for size), or z (for minimal size).

🌈 ENVIRONMENT 🌈

some of these affect only test harness programs (the ones generated via rustc --test); others affect all programs which link to the Rust standard library. read carefully, they're not all the same kind of thing.

  • RUST_TEST_THREADS β€” the test framework Rust provides executes tests in parallel. this variable sets the maximum number of threads used for that purpose. this setting is overridden by the --test-threads option.
  • RUST_TEST_NOCAPTURE β€” if set to a value other than "0", it's 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. your little "what even happened here" receipt 🫢

⭐ EXAMPLES ⭐

okay bestie here's what it actually looks like in the wild.

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

ate. every time. πŸ”₯


πŸ’… SEE ALSO πŸ’…


πŸ‘‘ BUGS πŸ‘‘

see https://github.com/rust-lang/rust/issues for issues. (if you found one… first of all sorry, second of all, tell them, they're lovely about it)


🧚 AUTHOR 🧚

see https://github.com/rust-lang/rust/graphs/contributors β€” or, if you're feeling fancy and you have the rust source distribution lying around, run this:

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

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


okay that's the whole page, bestie, you made it to the end and i'm so proud of you 🫢 one last thing for the sign-off β€” this was rustc 1.97.1 (8bab26f4f 2026-07...), dated April 2019, and it lives in section RUSTC(1) of the manual. go compile something cute. mwah. πŸ’–βœ¨

πŸ“¦ where this page comes from