RUSTC(1)

πŸ“¦ version 1.88.0, in ubuntu questing

πŸ’– RUSTC(1) β€” the manual, but make it cute πŸ’–

okay bestie, welcome to the User Commands section, this is the rustc page and she is iconic. grab a boba, we're going in πŸ§‹βœ¨


🌸 NAME 🌸

rustc β€” the Rust compiler. that's her. that's the whole name. she compiles Rust and she does it gorgeously πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

rustc [OPTIONS] INPUT

literally just rustc, then some [OPTIONS], then your INPUT. that's the whole vibe. no cap.


✨ DESCRIPTION ✨

so this program? it's a compiler for the Rust language, which lives at https://www.rust-lang.org. you give it Rust, it gives you... machine stuff. slay. it's giving main character energy, fr fr πŸ’œ


πŸ‘‘ OPTIONS πŸ‘‘

okay here's the whole flag menu, every single one, we're not skipping a thing:

  • -h, --help β€” shows you the help message. when in doubt, ask for help, bestie 🫢
  • --cfg SPEC β€” configures the compilation environment. that's the whole job.
  • -L [KIND=]PATH β€” adds a directory to the library search path. the KIND part is optional and can be one of these little cuties:
    • dependency β€” only look up transitive dependencies here
    • crate β€” only look up local extern crate directives here
    • native β€” only look up native libraries here
    • framework β€” only look for OSX frameworks here
    • all β€” look for anything here (this is the default, she's flexible πŸ’…)
  • -l [KIND=]NAME β€” links the generated crate(s) to the specified library NAME. KIND can be static, dylib, or framework. if you just... don't say, then dylib is assumed. she'll assume. πŸ™ˆ
  • --crate-type [bin|lib|rlib|dylib|cdylib|staticlib|proc-macro] β€” a comma separated list of types of crates for the compiler to emit.
  • --crate-name NAME β€” specify the name of the crate being built. name your baby.
  • --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 like, she said what she said. πŸ”₯
  • --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.
  • -g β€” equivalent to -C debuginfo=2. that's it, that's the whole thing, it's a shortcut bestie πŸ’–
  • -O β€” equivalent to -C opt-level=2. also just a shortcut. optimized and unbothered.
  • -o FILENAME β€” write output to FILENAME. ignored if multiple --emit outputs are specified which don't have an explicit path otherwise.
  • --out-dir DIR β€” write output to 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. she will explain herself, and honestly? she's right to.
  • --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 β€” prints 'lint' options and default settings.
  • -W OPT, --warn OPT β€” set lint warnings. gentle nudge energy πŸŽ€
  • -A OPT, --allow OPT β€” set lint allowed. she's cool with it, live your truth.
  • -D OPT, --deny OPT β€” set lint denied. nope. not today.
  • -F OPT, --forbid OPT β€” set lint forbidden. absolutely not, don't even try it πŸ’€
  • -C FLAG[=VAL], --codegen FLAG[=VAL] β€” set a codegen‐related flag to the value specified. use -C help to print available flags. see CODEGEN OPTIONS below, there's a whole section, she's thorough.
  • -V, --version β€” prints version info and exits. just the facts, then she's gone ✌️
  • -v, --verbose β€” use verbose output. she's gonna tell you everything, bestie.
  • --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.

  • --extern NAME=PATH β€” specify where an external rust library is located. these should match extern declarations in the crate's source code.
  • --sysroot PATH β€” override the system root.
  • -Z FLAG β€” set unstable / perma-unstable options. use -Z help to print available options. (iykyk πŸ‘€)
  • --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 girlies. absolutely gorgeous, every one:

  • 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.
  • remark=val β€” print remarks for these optimization passes (space separated, or "all").
  • no-stack-check β€” disable checks for stack exhaustion (a memory‐safety hazard!).
🚨 bestie. it literally says memory-safety hazard. that's the manpage's own words, i'm just holding the megaphone. be careful with this one. 😭
  • 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, mixed audience:

  • 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. (genuinely so useful, keep her in your .zshrc, periodt πŸ’…)

πŸ“ 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

ate. every single one. πŸ”₯


πŸŽ€ SEE ALSO πŸŽ€

her sister page. go read it after this, family support πŸ’–


πŸ’€ BUGS πŸ’€

see https://github.com/rust-lang/rust/issues for issues. (yes the manpage just sends you to the issue tracker. iconic honestly.)


🌟 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

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 fluent 🫢

sign-off szn: this is rustc version <INSERT VERSION HERE>, dated April 2019 β€” and yes, the manual name is literally RUSTC(1), we just folded it up here at the bottom with a little bow πŸŽ€

go compile something beautiful βœ¨πŸ’…πŸ‘‘

πŸ“¦ where this page comes from