RUSTC(1)
π 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. theKINDpart is optional and can be one of these lil guys: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 is the default)
-l [KIND=]NAMEβ links the generated crate(s) to the libraryNAMEyou picked. the optionalKINDcan bestatic,dylib, orframework. if you don't say anything,dylibis 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 outputPATHspecified for that particular emission kind. this path takes precedence over the-ooption, 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 toFILENAME. it's ignored if multiple--emitoutputs are specified which don't have an explicit path otherwise. rude but true π--out-dir DIRβ writes output to a compilerβchosen filename inDIR. ignored if-ois 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 helpto 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. 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. yes, that distinction matters, don't come for me π
--extern NAME=PATHβ specifies where an external rust library is located. these should matchexterndeclarations in the crate's source code.--sysroot PATHβ overrides the system root.-Z FLAGβ sets unstable / perma-unstable options. use-Z helpto 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 throughllc -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 intonunits 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 carefuldebuginfo=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 levels0β3,s(optimize for size), orz(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-threadsoption.RUST_TEST_NOCAPTUREβ if set to a value other than"0", 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. 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 π
β COPYRIGHT β
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
- ubuntu stonking: rustc-1.95 1.95.0+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