tldr/pages/common/rustc.md

34 lines
885 B
Markdown
Raw Normal View History

2016-05-05 02:51:41 +01:00
# rustc
> The Rust compiler.
2023-06-22 20:04:42 +01:00
> Rust projects usually use `cargo` instead of invoking `rustc` directly.
> More information: <https://doc.rust-lang.org/rustc>.
2016-05-05 02:51:41 +01:00
2023-06-22 20:04:42 +01:00
- Compile a binary crate:
2016-05-05 02:51:41 +01:00
2023-06-22 20:04:42 +01:00
`rustc {{path/to/main.rs}}`
2016-05-05 02:51:41 +01:00
2023-06-22 20:04:42 +01:00
- Compile with optimizations (`s` means optimize for binary size; `z` is the same with even more optimizations):
2016-05-05 02:51:41 +01:00
2023-06-22 20:04:42 +01:00
`rustc -C lto -C opt-level={{0|1|2|3|s|z}} {{path/to/main.rs}}`
2016-05-05 02:51:41 +01:00
- Compile with debugging information:
2023-06-22 20:04:42 +01:00
`rustc -g {{path/to/main.rs}}`
2023-06-22 20:04:42 +01:00
- Explain an error message:
2023-06-22 20:04:42 +01:00
`rustc --explain {{error_code}}`
2023-06-22 20:04:42 +01:00
- Compile with architecture-specific optimizations for the current CPU:
2023-06-22 20:04:42 +01:00
`rustc -C target-cpu={{native}} {{path/to/main.rs}}`
2023-06-22 20:04:42 +01:00
- 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:
2023-06-22 20:04:42 +01:00
`rustc --target {{target_triple}} {{path/to/main.rs}}`