This document explains how to use the rust xtensa tools on Linux, building and flashing without xbuild or xargo, so its easier to run rls (Rust Language Syntax) for better integration on VsCode Rust extension (and probably other IDEs too).
Please if you use Windows and you can make it work, you can contribute forking this gist.
I couldn't use RustUp because i ran into different problems while linking the toolchain and usign the vscode extension. Probably could be integrated someway.
⚡ If you want to skip the compiling, download and install linux Deb package |
---|
Clone the repo
$ git clone https://github.com/MabezDev/rust-xtensa
$ cd rust-xtensa
$ ./configure --experimental-targets=Xtensa
Configure rust-xtensa/config.toml
Change the target so it can build your target
target = ["x86_64-unknown-linux-gnu", "xtensa-esp32-none-elf"]
Use this if you are going to work with esp32 only
target = ["x86_64-unknown-linux-gnu", "xtensa-esp8266-none-elf"]
Or this if you are going to work with esp8266
target = ["x86_64-unknown-linux-gnu", "xtensa-esp32-none-elf", "xtensa-esp32s2-none-elf", "xtensa-esp8266-none-elf"]
Or this one if you are going to work with both.
Now due to a bug on the docs generation, ensure to not generate the docs, change this two lines
docs = false
compiler-docs = false
Set the extended compilation to true
extended = true
So we generate all rust tools (including rls, rustfms, etc...)
Now we need to specify where to install it, you have two options:
- Install it directly into ~/.local, this way you won't need to set env variables like RUSTC
- Install it somewhere else, then add the ENV variables
If you choose to install it into ~/.local
, set
prefix = "~/.local"
otherwise set into the folder you want, ensuring your user has the rights to write.
Change the sysconfdir to any folder your user has rights to write
sysconfdir = "~/rustetc"
After the build, you can copy the contents of this folder to /etc with root permissions, to add some cargo integrations to bash (optional).
Now, build and install!
$ ./x.py build --stage 2
$ ./x.py install
This will take a good amount of time, so relax.
For this example I will use xtensa-rust-quickstart
.
clone the repo
$ git clone git@github.com:MabezDev/xtensa-rust-quickstart.git
Add this to Cargo.toml in case you are going to use esp32
[features]
default = ["xtensa-lx-rt/lx6", "xtensa-lx/lx6", "esp32-hal"]
otherwise (esp8266)
[features]
default = ["xtensa-lx-rt/lx106", "xtensa-lx/lx106", "esp8266-hal"]
and create the file .vscode/settings.json
with this if you are going to use esp32
{
"rust-client.disableRustup": true,
"rust.all_targets": false,
"rust.target": "xtensa-esp32-none-elf"
}
or this if you are going to use esp8266
{
"rust-client.disableRustup": true,
"rust.all_targets": false,
"rust.target": "xtensa-esp8266-none-elf"
}
At this point make sure to have your esp idf tools installed, if you don't follow the official instructions.
For this what i have done is the following.
i added this line to ~/.bashrc
PROMPT_COMMAND='if [[ "$bashrc" != "$PWD" && "$PWD" != "$HOME" && -e .bashrc ]]; then bashrc="$PWD"; . .bashrc; fi'
That will make any program execute ./bashrc if it exists in his current folder.
And then you should create a .bashrc
file on your project root, with this
. $HOME/repo/esp/esp-idf/export.sh # this will add esp idf ENVS
And if you decided to install rust on another folder than /.local
, add this
PATH=<rust-folder>:$PATH
Now you can open the project in VsCode, with the Rust lang extension and you should be able to see the linting working.
For building the esp32 example use cargo build --example esp32
For building the esp8266 example use cargo build --example esp8266
For flashing the esp32 example use cargo espflash --release --chip esp32 --example esp32 --speed 460800 /dev/ttyUSB0 --tool cargo
For flashing the esp8266 example use cargo espflash --release --chip esp8266 --example esp8266 --speed 460800 /dev/ttyUSB0 --tool cargo
If you encounter problems on duplicate symbols on linking, try building again or deleting target directory and building again. As rare as its the way it worked me.
I hope this helps you as it helped me, Brian