chapter three

3 Project structure and configuration

 

This chapter covers

  • Embedded Rust project structure overview
  • Cargo file configurations (Cargo.toml, Cargo.lock, the optional Embed.toml)
  • Build system and linker script configuration (.cargo/config.toml, memory.x, the optional build.rs)
  • Managing features and dependencies using Cargo
  • Configuring Rust for no_std embedded environments and using common PACs and HALs

Chapter 2 detailed the setup of an embedded Rust development environment and introduced the essential tools involved. We saw that a pragmatic approach can be used to establish the basic project structure. In particular, using the cargo generate sub-command together with a suitable project template allows us to get up and running quickly. Naturally, the depth and quality of the resulting project depend heavily on the quality of the chosen template. It is not uncommon for such templates to become outdated when their authors stop maintaining them. As a consequence, embedded Rust developers eventually need to build a more thorough understanding of how to structure a project manually. Building directly upon these foundations, Chapter 3 will explore the manual process of structuring and configuring embedded Rust projects in greater depth.

3.1 Understanding Rust embedded project structure

3.1.1 A typical embedded Rust project layout

3.1.2 The role of Cargo.toml in embedded projects

3.1.3 Cargo.lock: Ensuring dependency reproducibility

3.1.4 Optional: Embed.toml and advanced tool integration

3.2 Build system & linker configuration

3.2.1 Defining memory layout with memory.x

3.2.2 Optional build-time customization with build.rs

3.2.3 The role of .cargo/config.toml in embedded Rust

3.3 Managing features & dependencies in Cargo

3.3.1 The importance of features in embedded Rust

3.3.2 Defining features in Cargo.toml

3.3.3 Target-specific dependencies

3.3.4 Discovering and Understanding Features in Dependencies

3.4 Configuring no_std for embedded systems

3.4.1 What does no_std mean in embedded Rust?

3.4.2 How to set-up a no_std project

3.4.3 A minimal bare-metal no_std example

3.5.1 Core architecture crates