Targets and cross compilation
Quick answer
Cross-compilation builds for a target different from the host running the compiler. A target triple selects a machine and environment contract, not a particular circuit board.
Check the target and ABI
For a Cortex-M4 candidate, thumbv7em-none-eabi is a bare-metal soft-float ABI target. The eabihf variant has a hard-float ABI and requires compatible hardware and linked objects. Use a board-specific linker layout and startup code for a real binary. A library check does not link firmware or test peripherals. Commands assume rustup and a trusted no_std library project.
Manual terminal step; not executed. Expected behavior (environment dependent):
Host triple, compiler details and installed target list.Record the exact compiler and installed targets before choosing one.
rustup target add thumbv7em-none-eabi --toolchain 1.85.0cargo +1.85.0 check --lib --target thumbv7em-none-eabiManual terminal step; not executed. Expected behavior (environment dependent):
Target installation requires network; compatible library checks or reports errors.This is not a flashable firmware build.
Common mistake
Do not select a target solely because the CPU name looks similar.
Try it yourself
Find your hypothetical board CPU, floating-point ABI and flash/RAM layout before selecting a target.
Static examples for Rust 1.85.0, edition 2024. Run them locally in a disposable project; ByteMind execution support and these outputs have not been verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Targets and cross compilation — practice quiz
Choose one answer per question. Code examples are predictions; review explanations after attempting them.
Two Cortex-M targets differ by hard-float ABI. What must linked native objects match?
Targets and cross compilation — example 1. Read the code; do not execute it for this question. Assume the lesson’s stated setup, compatible dependencies and toolchain, and a fresh disposable directory for file-creating examples. ```bash rustc -Vv rustup target list --installed ``` Which outcome or interpretation best matches this example?
Targets and cross compilation — example 2. Read the code; do not execute it for this question. Assume the lesson’s stated setup, compatible dependencies and toolchain, and a fresh disposable directory for file-creating examples. ```bash rustup target add thumbv7em-none-eabi --toolchain 1.85.0 cargo +1.85.0 check --lib --target thumbv7em-none-eabi ``` Which outcome or interpretation best matches this example?