4.1 Compiling Rust Code: rustc

The core tool for turning Rust source code into executable programs or libraries is the Rust compiler, rustc. For a very simple project contained in a single file, you can invoke it directly:

rustc main.rs

This command compiles main.rs and produces an executable file (named main on Linux/macOS, main.exe on Windows) in the current directory.

While functional, manually invoking rustc quickly becomes impractical for projects involving multiple source files, external libraries (dependencies), or different build configurations (like debug vs. release builds). This mirrors the complexity of managing non-trivial C/C++ projects with direct compiler calls, which led to the development of tools like Make and CMake. In Rust, the standard solution is Cargo.