RUSTC(1)
β¨ 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 herecrateβ only lookup localextern cratedirectives herenativeβ only lookup native libraries hereframeworkβ only look for OSX frameworks hereallβ 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 bestatic,dylib, orframework. if you skip it entirely,dylibis 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 outputrustcwill 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-ooption. 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--emitoutputs 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-ois 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 helpto 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. thefrom=toparameter is scanned from right to left, sofrommay contain'=', buttomay 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 helpto 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 throughllc -mcpu=help.passes=valβ a space-separated list of extra LLVM passes to run. a value of'list'will causerustcto 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 levels0β3,s(optimize for size), orz(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-threadsoption.RUST_TEST_NOCAPTUREβ if set to a value other than"0", it's a synonym for the--nocaptureflag.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
πΈ COPYRIGHT πΈ
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
- ubuntu stonking: rustc-1.97 1.97.1+dfsg-0ubuntu1 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms