Skip to content

Instantly share code, notes, and snippets.

@theronic
Forked from antoinevg/xtensa-rust.md
Last active December 22, 2019 09:16
Show Gist options
  • Save theronic/4ddf98781ef07af51af841f62b82f49f to your computer and use it in GitHub Desktop.
Save theronic/4ddf98781ef07af51af841f62b82f49f to your computer and use it in GitHub Desktop.
How to compile a version of Rust for the Xtensa to compile for ESP32

Like this:

# Use absolute paths, since relative paths like ~/Projects won't be expanded.

# - deps ------------------------------------------------------------------

sudo port install ninja  # or brew install ninja
cargo install xargo

# - build llvm ------------------------------------------------------------

cd /mnt/flowdsp/deps/versions/rust-xtensa
git clone https://github.com/espressif/llvm-xtensa.git llvm-xtensa.git
git clone https://github.com/espressif/clang-xtensa.git llvm-xtensa.git/tools/clang

mkdir llvm_build
cd llvm_build
CGLAGS=-O2 cmake ../llvm-xtensa.git -DLLVM_TARGETS_TO_BUILD="Xtensa;X86" -DCMAKE_BUILD_TYPE=Release -G "Ninja"
cmake --build .


# - build rustc -----------------------------------------------------------

cd /mnt/flowdsp/deps/versions/rust-xtensa
git clone https://github.com/MabezDev/rust-xtensa.git rust-xtensa.git

cd rust-xtensa.git
mkdir ../rustc_build
CGLAGS=-O2 ./configure --llvm-root="/mnt/flowdsp/deps/versions/rust-xtensa/llvm_build" --prefix="/mnt/flowdsp/deps/versions/rust-xtensa/rustc_build"
python ./x.py --help   # this fetches things from git.
python ./x.py build
python ./x.py install


# - link to rustup --------------------------------------------------------

rustup toolchain link xtensa "/mnt/flowdsp/deps/versions/rust-xtensa/rustc_build"
rustup run xtensa rustc --print target-list | grep xtensa


# - hello world  ----------------------------------------------------------

export IDF_PATH=/mnt/flowdsp/deps/esp-idf
cd $IDF_PATH
. ./export.sh

cd /mnt/flowdsp/deps/versions/rust-xtensa/xtensa-blinky.git  # where is this?
source setenv

cd components/rust
rustup run xtensa xargo build --target xtensa-esp32-none-elf --release

ulimit -n 1024 && idf.py build
ulimit -n 1024 && idf.py -p /dev/cu.SLAB_USBtoUART flash && idf.py -p /dev/cu.SLAB_USBtoUART monitor

https://gist.github.com/antoinevg/a4070a29005b8096efbfe1a6c610bbbe

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