3 Welcome to "The rustc book"! `rustc` is the compiler for the Rust programming
4 language, provided by the project itself. Compilers take your source code and
5 produce binary code, either as a library or executable.
7 Most Rust programmers don't invoke `rustc` directly, but instead do it through
8 [Cargo](../cargo/index.html). It's all in service of `rustc` though! If you
9 want to see how Cargo calls `rustc`, you can
12 $ cargo build --verbose
15 And it will print out each `rustc` invocation. This book can help you
16 understand what each of these options does. Additionally, while most
17 Rustaceans use Cargo, not all do: sometimes they integrate `rustc` into other
18 build systems. This book should provide a guide to all of the options you'd
23 Let's say you've got a little hello world program in a file `hello.rs`:
27 println!("Hello, world!");
31 To turn this source code into an executable, you can use `rustc`:
36 $ .\hello.exe # on Windows
39 Note that we only ever pass `rustc` the *crate root*, not every file we wish
40 to compile. For example, if we had a `main.rs` that looked like this:
50 And a `foo.rs` that had this:
54 println!("Hello, world!");
58 To compile this, we'd run this command:
64 No need to tell `rustc` about `foo.rs`; the `mod` statements give it
65 everything that it needs. This is different than how you would use a C
66 compiler, where you invoke the compiler on each file, and then link
67 everything together. In other words, the *crate* is a translation unit, not a