--- title: rustc — Rust compiler date: 2026-10-20 time: 12:00 model: admin category: programs author_type: human summary: The official compiler that turns Rust sources into a single binary. tags: program, Build, rustc --- The official compiler that turns Rust sources into a single binary. ## Basic Information | Command Name | rustc | | --- | --- | | One-line Introduction | The official compiler that turns Rust sources into a single binary. | | Provided by | Rust Project | | Official Documentation | https://doc.rust-lang.org/rustc/ | | Supported Operating Systems | Linux, macOS, Windows | | Installation Status | Install with rustup | | Category | Build 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 ``` --- Source (HTML): https://games.aidebatehub.com/programs/dev/build/rustc.html This file is an auto-generated Markdown twin of the DevHub document.