Skip to content

Instantly share code, notes, and snippets.

@kelnos
Last active February 22, 2021 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelnos/e1db69cfda9e1a60feb46488e02a70a3 to your computer and use it in GitHub Desktop.
Save kelnos/e1db69cfda9e1a60feb46488e02a70a3 to your computer and use it in GitHub Desktop.
Building esp32-wifi against Rust 1.50.0 using ESP-IDF 4.2
  1. Grab the following:
  2. If you've downloaded the Rust tarball, unpack to /opt/xtensa. If you are building from source, use the script provided in this gist (rust-xtensa-build) to build it.
  3. Install form: cargo install form
  4. Install svdtools (requires python 3.6 or above): pip3 install --upgrade --user svdtools
  5. Install an old-ish version of svd2rust using: cargo install --git https://github.com/rust-embedded/svd2rust --rev 29129c0e4e261bf4c38057f7585e7ddfc05fafd0 -- svd2rust
  6. Fetch version 4.2 of ESP-IDF (https://github.com/espressif/esp-idf/archive/v4.2.tar.gz), and unpack it somewhere. Set the IDF_PATH env var to its location (actually I don't think you need this unless you are regenerating the rust bindings in esp32-wifi).
  7. Fetch the latest ESP32 toolchain/binutils (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-tools.html#xtensa-esp32-elf) and unpack in /opt/xtensa.
  8. Grab the provided rust-xtensa script and source it into your shell session.
  9. In the esp32 crate source, run make.
  10. In the esp32-wifi checkout, create a file called rust-toolchain that just contains the word nightly, and run cargo xbuild --example test.
root=/opt/xtensa
rust=$root/rust
export RUST_BACKTRACE=full
export XARGO_RUST_SRC=$rust/lib/rustlib/src/rust/library
export RUST_SRC_PATH=$XARGO_RUST_SRC
export RUSTC=$rust/bin/rustc
export RUSTDOC=$rust/bin/rustdoc
export PATH=$rust/bin:$PATH:$root/xtensa-esp32-elf/bin
#!/bin/bash
set -e
prefix=/opt/xtensa/rust
channel=nightly
base_debug_args="--enable-debug --disable-optimize --disable-optimize-llvm --enable-llvm-release-debuginfo"
jobs=$(($(nproc)-2))
clean=true
build=true
install=true
hostmach=unknown
hostabi=gnu
checkarg() {
[ "$2" ] || {
echo "'$1' requires an argument" >&2
exit 1
}
}
while [ "$1" ]; do
case "$1" in
--prefix)
checkarg "$1" "2"
prefix=$2
shift
;;
--channel)
checkarg "$1" "$2"
channel=$2
shift
;;
--debug)
extra_configure_args="$base_debug_args"
;;
--debug-assert)
extra_configure_args="$base_debug_args --enable-llvm-assertions --enable-debug-assertions"
;;
--jobs|-j)
checkarg "$1" "$2"
jobs=$2
shift
;;
--host-mach)
checkarg "$1" "$2"
hostmach=$2
shift
;;
--host-abi)
checkarg "$1" "$2"
hostabi=$2
shift
;;
--no-clean)
clean=false
;;
--no-build)
build=false
;;
--no-install)
install=false
;;
*)
echo "Unknown option '$1'" >&2
exit 1
;;
esac
shift
done
hostarch=$(uname -m)-$hostmach-$(uname -s | tr '[A-Z]' '[a-z]')-$hostabi
if [ "$clean" = "true" ]; then
git clean -xfd
fi
if [ "$build" = "true" ]; then
./configure \
--prefix=$prefix \
--release-channel=$channel \
--experimental-targets=Xtensa \
--disable-docs \
--disable-compiler-docs \
$extra_configure_args
./x.py build --stage 2 --jobs $jobs
fi
if [ "$install" = "true" ]; then
rm -rf $prefix/* || true
./x.py install
mkdir -p $prefix/lib/rustlib/src/rust
cp -av Cargo.lock library $prefix/lib/rustlib/src/rust
mkdir -p $prefix/lib/rustlib/$hostarch
cp -av build/$hostarch/llvm/bin $prefix/lib/rustlib/$hostarch/
cp -av build/$hostarch/stage2/lib/rustlib/$hostarch/ $prefix/lib/rustlib/$hostarch/
fi
  • Figure out why the output of the latest rust2svd doesn't work with our esp32-hal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment