RUSTC(1)
π¦ RUSTC(1) β the one and only Rust compiler, bestie π
okay so real quick, this page lives in the User Commands section of the manual, and it's literally the whole personality of Rust in one command. come sit with me. π«Ά
β¨ NAME β¨
rustc β The Rust compiler. that's it. that's the queen. π
πΈ SYNOPSIS πΈ
rustc [OPTIONS] INPUT
π DESCRIPTION π
This program is a compiler for the Rust language, available at https://www.rust-lang.org.
likeβ¦ it compiles Rust. that's the vibe. no notes. β¨
π OPTIONS π
so many flags. we love a flag moment. here's every single one, no skipping, i promised.
-h,--helpβ Display the help message. your first stop when you're lost, and honestly same.--cfg SPECβ Configure the compilation environment.-L [KIND=]PATHβ Add a directory to the library search path. The optionalKINDcan be one of: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 (the default)
-l [KIND=]NAMEβ Link the generated crate(s) to the specified libraryNAME. The optionalKINDcan be one ofstatic,dylib, orframework. If omitted,dylibis assumed.--crate-type [bin|lib|rlib|dylib|cdylib|staticlib]β Comma separated list of types of crates for the compiler to emit.--crate-name NAMEβ Specify the name of the crate being built.--emit [asm|llvm-bc|llvm-ir|obj|link|dep-info|mir][=PATH]β Configure the output thatrustcwill produce. Each emission may also have an optional explicit outputPATHspecified for that particular emission kind. This path takes precedence over the-ooption. π--print [crate-name|file-names|sysroot|cfg|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|native-static-libs]β Comma separated list of compiler information to print on stdout.-gβ Equivalent to-C debuginfo=2.-Oβ Equivalent to-C opt-level=2.-o FILENAMEβ Write output toFILENAME. Ignored if multiple--emitoutputs are specified which don't have an explicit path otherwise.--out-dir DIRβ Write output to compiler-chosen filename inDIR. Ignored if-ois specified. Defaults to the current directory.--explain OPTβ Provide a detailed explanation of an error message.--testβ Build a test harness.--target TARGETβ Target triple for which the code is compiled. This option defaults to the host's target triple. The target triple 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β Print 'lint' options and default settings.-W OPT,--warn OPTβ Set lint warnings.-A OPT,--allow OPTβ Set lint allowed.-D OPT,--deny OPTβ Set lint denied.-F OPT,--forbid OPTβ Set lint forbidden.-C FLAG[=VAL],--codegen FLAG[=VAL]β Set a codegen-related flag to the value specified. Use-C helpto print available flags. See CODEGEN OPTIONS below.-V,--versionβ Print version info and exit.-v,--verboseβ Use verbose output.--remap-path-prefix from=toβ Remap 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.
--extern NAME=PATHβ Specify where an external rust library is located. These should matchexterndeclarations in the crate's source code.--sysroot PATHβ Override the system root.-Z FLAGβ Set internal debugging options. Use-Z helpto print available options.--color auto|always|neverβ Configure coloring of output:autoβ colorize, if output goes to a tty (default);alwaysβ always colorize output;neverβ never colorize output.
π₯ CODEGEN OPTIONS π₯
these are the -C besties. the deep lore. π
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 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.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.remark=valβ Print remarks for these optimization passes (space separated, or"all").no-stack-checkβ Disable checks for stack exhaustion (a memory-safety hazard!). π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 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.
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.
π¦ EXAMPLES π¦
the little moments. copy these. they work.
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) β the other icon. they're a duo, fr fr.
π BUGS π
See https://github.com/rust-lang/rust/issues for issues. (yes bestie, we know, we know. π)
π AUTHOR π
See https://github.com/rust-lang/rust/graphs/contributors or use git log --all --format='%cN <%cE>' | sort -u in the rust source distribution.
π COPYRIGHT π
This work is dual-licensed under Apache 2.0 and MIT terms. See COPYRIGHT file in the rust source distribution.
and that's the whole page, bestie π no cap, you now know rustc better than half the internet. π
signing off from the rustc corner of the manual β version placeholder and all β dated April 2019, straight out of the RUSTC(1) crew.*** π
β¨
π¦ where this page comes from
- ubuntu jammy: rustc-1.62 1.62.1+dfsg1-1ubuntu0.22.04.3 Β· 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