Properties2
TypeConcept
Note createdFeb 17, 2025

Rust, being a compiled language, has clearly differentiated compilation and running steps. The compilation is done using the rustc tool:

rustc main.rs

Running, on the other hand, is done using the generated binaries.

./main

Rust is an ahead-of-time compiled language, so the generated binaries are self-contained and can be run in a machine with no Rust runtime installed (if the architecture matches).

Compiling using Cargo

Most of the times, when trying to compile a complete project, it is a good idea to delegate the use of rustc to Cargo. To do so, navigate to a Cargo project and run:

cargo build [--release]

To generate the binaries in the ./target directory. There, you can find different directories for different configurations like debug, release, etc. When using the --release flag, Cargo will compile the code with optimizations. It will run faster, but will take longer compile.

It is also important to note that there is a shorthand to both compile and run the code using:

cargo run