Skip to content

Instantly share code, notes, and snippets.

@antoinevg
Last active September 9, 2021 10:58
Show Gist options
  • Save antoinevg/a4070a29005b8096efbfe1a6c610bbbe to your computer and use it in GitHub Desktop.
Save antoinevg/a4070a29005b8096efbfe1a6c610bbbe to your computer and use it in GitHub Desktop.

Adapted from:

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

Like this:

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

sudo port install ninja
cargo install xargo

mkdir /mnt/flowdsp/deps/esp-rust
mkdir /mnt/flowdsp/deps/esp-rust/output
mkdir /mnt/flowdsp/deps/esp-rust/output/llvm
mkdir /mnt/flowdsp/deps/esp-rust/output/rust


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

cd /mnt/flowdsp/deps/esp-rust
git clone https://github.com/espressif/llvm-project.git llvm-project.git

cd llvm-project.git/llvm
mkdir build
cd build

# https://llvm.org/docs/GettingStarted.html
CFLAGS=-O2 cmake .. -DCMAKE_INSTALL_PREFIX=/mnt/flowdsp/deps/esp-rust/output/llvm -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="Xtensa;X86" -DCMAKE_BUILD_TYPE=Release -G "Ninja"

cmake --build .
cmake --install .


# - build rust-xtensa -----------------------------------------------------

acd /mnt/flowdsp/deps/esp-rust
git clone https://github.com/MabezDev/rust-xtensa.git rust-xtensa.git

cd rust-xtensa.git
git checkout xtensa-target

CFLAGS=-O2 ./configure --llvm-root="../llvm-project.git/llvm/build" --prefix="../output/rust"

python ./x.py --help
python ./x.py build
python ./x.py install


# - xtensa-esp32-elf toolchain --------------------------------------------

# Basically: https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html#linux-and-macos

cd /mnt/flowdsp/deps/esp-rust
cp -a ~/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0 output/esp-2019r2-8.2.0-osx


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

rustup toolchain link xtensa "/mnt/flowdsp/deps/esp-rust/output/rust"
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
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