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.
|
2019-05-23 11:56:50 +01:00
|
|
|
> 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}}`
|
2020-09-11 01:31:08 +01:00
|
|
|
|
2023-06-22 20:04:42 +01:00
|
|
|
- Explain an error message:
|
2020-09-11 01:31:08 +01:00
|
|
|
|
2023-06-22 20:04:42 +01:00
|
|
|
`rustc --explain {{error_code}}`
|
2020-09-11 01:31:08 +01:00
|
|
|
|
2023-06-22 20:04:42 +01:00
|
|
|
- Compile with architecture-specific optimizations for the current CPU:
|
2020-09-11 01:31:08 +01:00
|
|
|
|
2023-06-22 20:04:42 +01:00
|
|
|
`rustc -C target-cpu={{native}} {{path/to/main.rs}}`
|
2020-09-11 01:31:08 +01:00
|
|
|
|
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):
|
2020-09-11 01:31:08 +01:00
|
|
|
|
|
|
|
`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}}`
|