liveBook · Manning

Cargo

As explained in Embedded Software with Rust

Cargo is Rust's package manager and build system, providing dependency management, compilation, testing, and related project workflows.

Cargo coordinates embedded Rust builds and project workflows. Bare-metal projects use explicit target configuration; Cargo also manages dependencies and features that can select different build behavior. section 1.7.1 section 6.4.5

In embedded projects, Cargo supports:

  • Building for an explicitly selected Arm Cortex-M or RISC-V target. section 1.7.1
  • Working with tools to convert and inspect firmware binaries. section 2.8
  • Using project configuration to set a target, runner, and linker script without repeating command-line options. section 3.2.3
  • Keeping dependency versions reproducible through Cargo.lock, which Cargo manages automatically. section 3.1.3
[target.thumbv7m-none-eabi]
runner = "gdb-multiarch -q -x openocd.gdb"

rustflags = [
  "-C", "link-arg=-Tlink.x",
]

[build]
target = "thumbv7m-none-eabi"

This configuration sets a Cortex-M target, a GDB/OpenOCD runner, and a linker script for the build. section 3.2.3

Choose panic behavior with a feature

A debug-panic Cargo feature selects semihosting output; a build without that feature selects a silent halt handler. The same source tree can produce either variant. section 6.4.5

// Cargo.toml

[features]
debug-panic = []

[dependencies]
panic-halt        = "1.0"
panic-semihosting = "0.6"

The manifest listing declares the debug-panic feature and the two candidate panic-handler dependencies. section 6.4.5

// main.rs

#[cfg(feature = "debug-panic")]
use panic_semihosting as _;

#[cfg(not(feature = "debug-panic"))]
use panic_halt as _;

The conditional imports link exactly one panic handler, according to whether debug-panic is enabled. section 6.4.5

How Embedded Software with Rust covers it

How deep it goes
Configures targets, runners, linker flags, dependency locks, and feature-selected panic handlers; broader binary workflows are outlined.
Examples
Uses a Cortex-M target with a GDB/OpenOCD runner and feature-selected semihosting or halt panic handlers.
What you can do after
Configure embedded targets, runners, and linker settings, then build diagnostic or silent panic variants with Cargo features.
How it connects
Connects to rustup, no_std, Cargo features, Cargo.lock, linker scripts, and embedded runners.

Also explained in

Compare how 7 books explain Cargo →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Embedded Software with Rust. The section links point to the parts of the book it draws on.