chapter eight
8 Rust-C Integration and Migration
This chapter covers
- What an Application Binary Interface (ABI) promises, and how the AAPCS shapes every Rust-C call on Cortex-M
- Calling C from Rust: type mapping,
#[repr]discipline, safe wrappers, and linking - Calling Rust from C: exported symbols,
no_stdstatic libraries, and error codes that cross the boundary - The hard cases: buffers, strings, and callbacks with context
- Automating both directions with bindgen and cbindgen, aimed at the right target
- Incrementally migrating an existing C firmware codebase to Rust
Nearly every embedded Rust project eventually runs into someone else’s C: a vendor’s HAL, a protocol stack nobody has time to reimplement, an RTOS kernel that already runs on the board. Rust’s usual promises, memory safety, a strict compiler, don’t extend across a language boundary automatically; the moment C and Rust need to share a function call or a piece of memory, you’re responsible for making the two sides agree by hand, using the tools this chapter covers.