Rust compiles for targets defined in JSON specification files. The upstream Rust distribution includes hundreds of targets (x86_64-unknown-linux-gnu, thumbv7em-none-eabihf, etc.). For a custom MCU not in the distribution, you write your own.

Minimal custom RISC-V target:

{
  "arch": "riscv32",
  "cpu": "generic-rv32",
  "data-layout": "e-m:e-p:32:32-i64:64-n32-S128",
  "emit-debug-gdb-scripts": false,
  "features": "+m,+a,+c",
  "linker": "rust-lld",
  "linker-flavor": "ld.lld",
  "llvm-target": "riscv32",
  "max-atomic-width": 32,
  "panic-strategy": "abort",
  "relocation-model": "static",
  "target-pointer-width": "32"
}

features: RISC-V ISA extensions. +m = multiply/divide, +a = atomic instructions, +c = compressed instructions. Matching the exact ISA of your target is critical — enabling an extension your CPU doesn't have causes illegal instruction traps.

Used in Cerberus-OS to target a custom RV32IMAC configuration where the standard riscv32imac-unknown-none-elf target needed modification for the specific memory model and ABI requirements.