LinuxCommandLibrary

rustc

Rust programming language compiler

TLDR

Compile a Rust file

$ rustc [main.rs]
copy
Compile with output name
$ rustc [main.rs] -o [program]
copy
Compile with optimizations
$ rustc -O [main.rs]
copy
Compile in release mode
$ rustc -C opt-level=3 [main.rs]
copy
Compile with debugging info
$ rustc -g [main.rs]
copy
Show warnings
$ rustc -W warnings [main.rs]
copy
Emit assembly
$ rustc --emit=asm [main.rs]
copy
Emit LLVM IR
$ rustc --emit=llvm-ir [main.rs]
copy
Check without compiling
$ rustc --emit=metadata [main.rs]
copy
Show version
$ rustc --version
copy

SYNOPSIS

rustc [options] input

DESCRIPTION

rustc is the compiler for the Rust programming language. It compiles Rust source code (.rs files) into executables or libraries. The compiler performs type checking, borrow checking, and optimization.
While rustc can be used directly, most Rust development uses Cargo which invokes rustc with appropriate settings. Direct rustc usage is common for simple programs, learning, or advanced build customization.
rustc uses LLVM for code generation, providing excellent optimization and support for many target platforms.

PARAMETERS

-o file

Output filename.
-O
Optimize (equivalent to -C opt-level=2).
-g
Include debug information.
-C option
Codegen options.
-W lint
Set lint warning level.
-A lint
Allow lint.
-D lint
Deny lint (make it error).
--emit= type
Output type (asm, llvm-ir, obj, link).
--crate-type= type
Crate type (bin, lib, dylib, staticlib).
--edition= year
Rust edition (2015, 2018, 2021).
--target= triple
Target platform.
--explain code
Explain an error code.
-L path
Add library search path.
--extern name=path
Specify external crate location.

CAVEATS

Direct rustc usage requires manual dependency management. Most projects should use Cargo instead. Edition differences may cause compatibility issues. Cross-compilation requires target toolchain installation.

HISTORY

rustc was developed as part of the Rust programming language project, started by Graydon Hoare at Mozilla in 2006. Rust reached version 1.0 in May 2015. The compiler was originally written in OCaml but was rewritten in Rust (self-hosted) by version 1.0. Development continues under the Rust Foundation, established in 2021.

SEE ALSO

cargo(1), rustup(1), rustfmt(1), clippy(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community