Korean

rustc — Rust compiler

Development / Build / rustc.html

BuildOriginalRegistered 2026-10-20T09:00:00+09:00

The official compiler that turns Rust sources into a single binary.

Basic Information

Command Namerustc
One-line IntroductionThe official compiler that turns Rust sources into a single binary.
Provided byRust Project
Official Documentationhttps://doc.rust-lang.org/rustc/
Supported Operating SystemsLinux, macOS, Windows
Installation StatusInstall with rustup
CategoryBuild and compile (tags: Language toolchain (tags: rustc, rust, compile, cargo))

What is this command?

rustc compiles Rust sources directly. Its ownership and borrow checks run at compile time, blocking many memory-safety issues before execution.

In practice cargo manages dependencies and build settings, while rustc serves single-file experiments or fine-grained control. Optimization and debug info are set with -C options.

What problems does it solve?

  • Trying Rust syntax in a single file
  • Building a binary without cargo
  • Controlling optimization and debug options directly
  • Learning from compiler diagnostics

Key features

Single-file build

Compile one source into a binary.

  • When to use: Testing syntax or an algorithm
  • What you get: You get a standalone binary.
  • Limitations: External crates must be linked manually.

Optimization level

-C opt-level controls optimization strength.

  • When to use: Benchmarking or release builds
  • What you get: Balance runtime performance against build time.
  • Limitations: Heavy optimization makes debugging harder.

Diagnostics

Explains ownership and borrow errors in detail.

  • When to use: Understanding why compilation failed
  • What you get: You get guidance on how to fix it.
  • Limitations: Messages can be long for newcomers.

Installation and usage

Check whether it is installed

rustc --version

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source "$HOME/.cargo/env"

Real-world examples

Compile one file

Build a binary with default optimization.

rustc main.rs -o app
./app

Release optimization

Raise optimization for distribution.

rustc -C opt-level=3 main.rs -o app

Include debug info

Build with symbols so a debugger can inspect variables.

rustc -g main.rs -o app-debug