2020-09-22 17:56:18 +01:00
|
|
|
# cargo rustc
|
|
|
|
|
2023-10-29 08:54:53 +00:00
|
|
|
> Compile a Rust package. Similar to `cargo build`, but you can pass extra options to the compiler.
|
|
|
|
> See `rustc --help` for all available options.
|
2020-09-22 17:56:18 +01:00
|
|
|
> More information: <https://doc.rust-lang.org/cargo/commands/cargo-rustc.html>.
|
|
|
|
|
2023-10-29 08:54:53 +00:00
|
|
|
- Build the package and pass options to `rustc`:
|
2020-09-22 17:56:18 +01:00
|
|
|
|
2023-10-29 08:54:53 +00:00
|
|
|
`cargo rustc -- {{rustc_options}}`
|
2020-09-22 17:56:18 +01:00
|
|
|
|
|
|
|
- Build artifacts in release mode, with optimizations:
|
|
|
|
|
|
|
|
`cargo rustc --release`
|
|
|
|
|
|
|
|
- Compile with architecture-specific optimizations for the current CPU:
|
|
|
|
|
|
|
|
`cargo rustc --release -- -C target-cpu=native`
|
|
|
|
|
2023-10-29 08:54:53 +00:00
|
|
|
- Compile with speed optimizations:
|
2020-09-22 17:56:18 +01:00
|
|
|
|
|
|
|
`cargo rustc -- -C opt-level {{1|2|3}}`
|
|
|
|
|
2023-10-29 08:54:53 +00:00
|
|
|
- Compile with [s]ize optimizations (`z` also turns off loop vectorization):
|
2020-09-22 17:56:18 +01:00
|
|
|
|
|
|
|
`cargo rustc -- -C opt-level {{s|z}}`
|
|
|
|
|
|
|
|
- Check if your package uses unsafe code:
|
|
|
|
|
|
|
|
`cargo rustc --lib -- -D unsafe-code`
|
|
|
|
|
|
|
|
- Build a specific package:
|
|
|
|
|
|
|
|
`cargo rustc --package {{package}}`
|
|
|
|
|
|
|
|
- Build only the specified binary:
|
|
|
|
|
|
|
|
`cargo --bin {{name}}`
|