2

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?

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
rnso
  • 23,686
  • 25
  • 112
  • 234

2 Answers2

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
3

In addition to custom or third party build system, there is about 2 scenarios where I would use rustc over cargo

  1. 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
  2. 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