RISC-V Targets Only

To build Rust applications for the Espressif chips based on RISC-V architecture, do the following:

  1. Install the nightly toolchain with the rust-src component:

    rustup toolchain install nightly --component rust-src

    The above command downloads the rust source code. rust-src contains things like the std-lib, core-lib and build-config files.
    Downloading the rust-src is 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 rustc uses the rust-src to 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 rust-src.

    For more info on custom targets, read this Chapter from the Embedonomicon.

  2. Set the target:

    • For 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

      This target is currently Tier 2. Note the different flavors of riscv32 target in Rust covering different RISC-V extensions.

    • For std applications:

      Since this target is currently Tier 3, it doesn't have pre-built objects distributed through rustup and, unlike the no_std target, nothing needs to be installed. Refer to the *-esp-idf section of the rustc book for the correct target for your device.

      • riscv32imc-esp-espidf for SoCs which don't support atomics, like ESP32-C2 and ESP32-C3
      • riscv32imac-esp-espidf for SoCs which support atomics, like ESP32-C6, ESP32-H2, and ESP32-P4
  3. To build std projects, you also need to install:

Now you should be able to build and run projects on Espressif's RISC-V chips.