rustc
Rust programming language compiler
TLDR
Compile a Rust file
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.
