Easy methods to compile Rust and LLVM for ESP32 on a Raspberry Pi (aarch64)

ESP32 is a collection of microcontrollers that has the particularity to have each built-in Bluetooth and Wi-Fi. It makes it the right microcontroller whenever you want low-power, networked, and sensible {hardware} that doesn’t require an OS.

I needed to run compile and run Rust code on an ESP32. Sadly, they don’t run a standard structure however the Xtensa instruction set that's at present not formally supported by the Rust compiler.

The esp-rs GitHub group incorporates the fork of the Rust compiler to assist the Xtensa structure.

Sadly, plainly the src/llvm-project submodule is outdated and doesn't assist the aarch64 (arm64) structure, as when attempting to observe the directions I encountered the next error:

cargo:warning=cc: error: esp32/rust/src/llvm-project/compiler-rt/lib/builtins/aarch64/lse.S: No such file or listing
cargo:warning=cc: deadly error: no enter information
cargo:warning=compilation terminated.
exit standing: 1

Which, in keeping with this issue, is because of an outdated LLVM model.

Right here is how I fastened the construct and efficiently constructed Rust and LLVM to compile Rust binaries for ESP32:

The stipulations

You will want at the least 20GB of free area and a Rust toolchain: https://rustup.rs.

Constructing Rust

# ranging from $HOME
$ mkdir esp32
$ cd esp32
$ git clone https://github.com/esp-rs/rust.git
$ cd rust

Right here is the trick: you want to replace the src/llvm-project submodule:

$ git submodule replace --init --recursive --remote src/llvm-project

Then, you may lastly construct Rust (warning: it should take numerous time, so I like to recommend to run it for the evening):

$ ./configure --experimental-targets=Xtensa
$ python3 x.py dist --stage 2
# nonetheless in esp32/rust
$ rustup toolchain hyperlink esp `pwd`/construct/aarch64-unknown-linux-gnu/stage2

Constructing LLVM

Nonetheless in your just lately cloned rust folder (warning: it should take numerous time, so I like to recommend to run it for the evening):

$ cd src/llvm-project
$ mkdir construct
$ cd construct
$ cmake -G Ninja -DLLVM_ENABLE_PROJECTS='clang' -DCMAKE_BUILD_TYPE=Launch ../llvm
$ cmake --build .
$ export PATH="$HOME/esp32/rust/src/llvm-project/construct/bin:$PATH"

Your Rust toolcahin for ESP32 is now arrange!

You'll be able to verify it by working:

$ rustc --print target-list | grep xtensa


Which ought to return your newly constructed clang.

See you tomorrow for a publish on how to build and flash a Rust program to an ESP32.

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *