I am trying to learn Rust programming language. I see that majority of the time one is working with cargo
command, e.g. cargo new
, cargo add
, cargo build
, cargo run
etc. When is rustc
command used instead of cargo
?
Asked
Active
Viewed 108 times
2

StayOnTarget
- 11,743
- 10
- 52
- 81

rnso
- 23,686
- 25
- 112
- 234
-
Relevant: https://stackoverflow.com/questions/38040327/how-to-pass-rustc-flags-to-cargo – E_net4 Apr 14 '23 at 13:43
2 Answers
5
Pretty much never.
Cargo handles a lot of the intricacies of building a Rust project for you, and you pretty much never have to leave it for "standard" development. The only reason not to use it is if you're forced to, like needing to use obscure options, outputting a different format like MIR, of if you need to use a different build system for whatever reason.

Colonel Thirty Two
- 23,953
- 8
- 45
- 85
-
Even in the cases you mentioned `cargo rustc` or `cargo build` with setting `RUSTFLAGS`. – Chayim Friedman Apr 14 '23 at 08:47
-
But `rustc` is sometimes used directly for custom build systems. – Chayim Friedman Apr 14 '23 at 08:48
3
In addition to custom or third party build system, there is about 2 scenarios where I would use rustc
over cargo
- I don't have a full blown cargo project because I'm compiling a single file toy code example with no dependencies other than
std
- I want the extended information for an error message
rustc --explain Exxxx
In all other cases just use cargo
it's built for handling all the dependency, file & folder layout, consistent configuration, etc. cases

cafce25
- 15,907
- 4
- 25
- 31