Link Search Menu Expand Document


The Rust compiler. Rust projects usually use cargo instead of invoking rustc directly. More information:

  • Compile a binary crate:

rustc {{path/to/}}

  • Compile with optimizations (s means optimize for binary size; z is the same with even more optimizations):

rustc -C lto -C opt-level={{0|1|2|3|s|z}} {{path/to/}}

  • Compile with debugging information:

rustc -g {{path/to/}}

  • Explain an error message:

rustc --explain {{error_code}}

  • Compile with architecture-specific optimizations for the current CPU:

rustc -C target-cpu={{native}} {{path/to/}}

  • Display the target list (Note: you have to add a target using rustup first to be able to compile for it):

rustc --print target-list

  • Compile for a specific target:

rustc --target {{target_triple}} {{path/to/}}