To build Rust applications for the Espressif chips based on
RISC-V architecture, do the following:
rustup toolchain install nightly --component rust-src
The above command downloads the rust source code.
rust-srccontains things like the std-lib, core-lib and build-config files.
rust-srcis important because of two reasons :
- Determinism - You get the chance to inspect the internals of the core and std library. If you are building software that needs to be determinate, you may need to inspect the libraries that you are using.
- Building custom targets - The
rust-srcto create the components of a new custom-target. If you are targeting a triple-target that is not yet supported by rust, it becomes essential to download the
Set the target:
no_std(bare-metal) applications, run:
rustup target add riscv32imc-unknown-none-elf # For ESP32-C2 and ESP32-C3 rustup target add riscv32imac-unknown-none-elf # For ESP32-C6 and ESP32-H2
Since this target is currently Tier 3, it doesn't have pre-built objects distributed through
rustupand, unlike the
no_stdtarget, nothing needs to be installed. Refer to the *-esp-idf section of the rustc book for the correct target for your device.
riscv32imc-esp-espidffor SoCs which don't support atomics, like ESP32-C2 and ESP32-C3
riscv32imac-esp-espidffor SoCs which support atomics, like ESP32-C6, ESP32-H2, and ESP32-P4
stdprojects, you also need to install:
Now you should be able to build and run projects on Espressif's