Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Building & Running · Lesson 8 of 8

cargo run vs cargo build

A free lesson from Swipe Coding · Rust, level 2 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
Same underlying compile step, two different jobs — knowing which one to reach for saves time. ⚙️

cargo build compiles your project into a runnable binary, but it doesn't run that binary for you — it just leaves it sitting in the target/debug folder, waiting. cargo run does both steps in one: it compiles the project (recompiling only if something changed since last time) and then immediately runs the resulting binary.

cargo build
./target/debug/my_project

# vs. doing both in one step:
cargo run
cargo build only compiles; you have to run the binary yourself. cargo run compiles and runs it for you.

There's also cargo check, which is faster than either: it asks the compiler to verify your code is correct without actually producing a runnable binary at all. It's handy while you're still writing code and just want quick feedback on whether it compiles.

Fill in the blank

Running ____ compiles a Rust project and then immediately runs the resulting binary, all in one step.

🤖
Debug builds are for you; release builds are for everyone else. 🚀

By default, both cargo build and cargo run produce a debug build: fast to compile, but not very optimized, and placed in target/debug. Adding the --release flag, as in cargo build --release, produces a much more optimized binary in target/release — it takes noticeably longer to compile, but the resulting program runs significantly faster, which is what you'd ship to real users.

cargo build --release
./target/release/my_project
Building an optimized release binary and running it directly from target/release.
True or false

Running cargo build without any flags produces an optimized binary in target/release.

Chapter quiz

Building & Running

10 questions · pass with 60% — just like in the app.

Quick check

What does cargo build do?

True or false

cargo run compiles the project and then immediately runs the resulting binary.

Fill in the blank

Running ____ verifies your code compiles without producing a runnable binary at all.

Quick check

Where does a default (non-release) cargo build place the compiled binary?

True or false

Passing --release to cargo build produces a more optimized binary that takes longer to compile.

Fill in the blank

Building with the ____ flag places an optimized binary in target/release instead of target/debug.

Quick check

Which command is generally fastest, since it skips producing a runnable binary?

True or false

A debug build compiled with plain cargo build runs just as fast as a --release build.

Quick check

What would you use during everyday development when you just want to try your code quickly?

Fill in the blank

An optimized binary meant for shipping to real users is typically built with cargo build ____.

Keep your streak going in Swipe Coding

Swipe through every level of Rust on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →