Skip to content

Instantly share code, notes, and snippets.

@eHammarstrom
Last active September 13, 2019 06:50
Show Gist options
  • Save eHammarstrom/82411f8ccebb5f096db7cb0ec6dbc25a to your computer and use it in GitHub Desktop.
Save eHammarstrom/82411f8ccebb5f096db7cb0ec6dbc25a to your computer and use it in GitHub Desktop.
esp32 rust

ESP32 Rust

Build LLVM for X86 (rustc) and Xtensa

  1. git clone https://github.com/espressif/llvm-xtensa.git
  2. git clone https://github.com/espressif/clang-xtensa.git llvm-xtensa/tools/clang
  3. mkdir llvm-xtensa-build && cd llvm-xtensa-build
  4. cmake ../llvm-xtensa -DLLVM_TARGETS_TO_BUILD="Xtensa;X86" -DCMAKE_BUILD_TYPE=Release -G "Ninja"
  5. cmake --build . -j X

Build & install rustc

  1. git clone --single-branch --branch xtensa-target https://github.com/MabezDev/rust rust-xtensa
  2. cd rust-xtensa && ./configure --llvm-root=$PATH_TO_LLVM_BUILD
  3. set prefix in cargo.toml, e.g. prefix=/opt/xtensa
  4. rust-lang/rust#40108 (comment)
  5. rustup toolchain link xtensa-esp32-elf /opt/xtensa
  6. rustup default xtensa-esp32-elf

Generate your project!

  1. cargo install cargo-generate
  2. cargo generate --git https://github.com/MabezDev/xtensa-rust-quickstart
  3. Edit setenv's CUSTROM_RUSTC and run source setenv e.g. CUSTOM_RUSTC=/home/estrom/git/rust-xtensa
  4. Debug builds are buggy, use xargo build --release

Known issues

Undefined reference to .L (MabezDev/xtensa-rust-quickstart#1) Add "--emit", "llvm-bc,link", to rustflags in .cargo/config.

xargo build may faild due to buggy debug builds, instead build in release mode xargo build --release.

Xtensa binutils / gcc

https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html#step-1-install-prerequisites

Resources used

https://github.com/MabezDev/xtensa-rust-quickstart

https://gist.github.com/MabezDev/26e175790f84f2f2b0f9bca4e63275d1

https://esp32.com/viewtopic.php?t=9226&p=38466

https://www.esp32.com/viewtopic.php?t=7400

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment