Originally published on php2rust.dev — part of the PHP to Rust course. View this lesson on the original site.

Cargo is Rust’s package manager and build orchestrator. One tool answers: Where does my code live? How do I compile it? Which libraries do I use? Are they the same versions my teammates use? In day-to-day work you rarely invoke rustc by hand for real projects, you let Cargo drive the toolchain.

If you’re coming from PHP, Cargo plays a role similar to Composer (dependencies and lockfiles), plus project scripts / build steps you might otherwise wire up with Make, shell scripts, or framework CLIs. It is the default, expected way to build and run Rust code in the ecosystem, not an optional extra.

Why Cargo exists

Rust cares about correctness and reproducibility. A nontrivial program is more than one .rs file: it has a root package, a manifest (Cargo.toml) that names the project and its dependencies, a layout (src/, tests, examples), and often multiple targets (your app, integration tests, benchmarks). Cargo encodes those conventions so tools, IDEs, and CI all agree on the same project shape.

Without something like Cargo, you’d be juggling compiler flags, paths to dependencies, and feature flags yourself. Cargo centralises that so you can focus on the program.

How it fits with the rest of the toolchain

  • rustup gives you Rust versions and targets (compiler + standard library for a platform).
  • rustc is the compiler for a single crate when invoked directly.
  • Cargo is what you use to build crates as a project: it calls rustc with the right options, in the right order, for your package and its dependency graph.

You already used rustc on a tiny file to see the bare metal. For everything after that, Cargo is the normal path.

Packages, crates, and Cargo.toml

Rust’s unit of publication and dependency is a crate (a library or an executable package). Cargo’s manifest, Cargo.toml, is roughly analogous to composer.json: project name, version, authors, dependencies, and settings. The companion Cargo.lock (generated for applications) pins exact versions so builds are repeatable, similar in spirit to composer.lock.

Public libraries are usually fetched from crates.io (Rust’s registry), which fills a similar niche to Packagist for PHP. You don’t need to master registries here; the point is that Cargo is the standard client for that workflow.

What you’ll do in practice

In real Rust development you’ll spend most of your time with Cargo driving build, run, test, and dependency updates, always against a well-defined project tree. The next lesson walks through Cargo’s main commands and what each one is for; here, the takeaway is the role: Cargo is the hub that connects your source, the compiler, and the ecosystem.

What's next

Next: Cargo's main features.

From PHP to Rust — Getting Started with Rust