Minimal ESP-IDF project that calls a Rust component from app_main().
alloc(default): buildscore + alloc + panic_abort, enablesesp-idf-svclogging, and prints throughlog::info!.no_alloc: buildscore + panic_abort, avoids allocator-backed dependencies, and prints throughesp_idf_sys::puts().
- Espressif Rust toolchain installed (
components/rust-hello_rust/rust-toolchain.tomluseschannel = "esp")
Example:
source ~/.espressif/v6.0/esp-idf/export.shThe checked-in sdkconfig currently targets esp32p4.
If you want a different chip, select it first:
idf.py set-target esp32p4Build with the default alloc mode:
idf.py buildFlash and monitor:
idf.py flash monitorThe Rust component exposes a CMake cache variable named RUST_MEMORY_MODEL.
Use the default alloc mode:
idf.py -DRUST_MEMORY_MODEL=alloc reconfigure buildSwitch to no_alloc mode:
idf.py -DRUST_MEMORY_MODEL=no_alloc reconfigure buildInternally this maps to Cargo features and build-std settings:
alloc->--features alloc-modeand-Zbuild-std=core,alloc,panic_abortno_alloc->--features no-alloc-modeand-Zbuild-std=core,panic_abort
main/main.c always prints:
Hello world from C!
Rust returned code: 42
The Rust-side output depends on the selected memory model:
alloc: emits an ESP log message similar toHello, world!no_alloc: printsHello, world from Rust (no_alloc)!
components/rust-hello_rust/src/lib.rsenforces that exactly one ofalloc-modeorno-alloc-modeis enabled at compile time.esp_idf_sys::link_patches()is still called before any Rust-side output so ESP-IDF runtime patches are linked correctly.components/rust-hello_rust/Cargo.tomlkeeps temporarymasterbranch patches foresp-idf-sys,esp-idf-hal,esp-idf-svc, andembuilduntil crates.io support for IDF 6.0 is available.