⚙️

Rust on ESP32 の環境構築で2日溶けた話

2025/02/21に公開

Conclusion

esp channel にターゲティングするには cargo +esp ~~

Target

https://github.com/esp-rs
https://lilygo.cc/products/t-watch-2020-v3?srsltid=AfmBOoqtYouWdlm4nJQCDLiRNCfX_PLbNGNgD0Xcf6qEHZh2-30VyoOC
※技適の実験届出が必要

Reference

https://lang-ship.com/blog/work/esp32-std-rust-1/
https://note.com/shirokumamake/n/na6c2897b9f82

起こったこと

これら Reference では,cargo (run or build)で成功している.
しかし筆者環境では

error[E0463]: can't find crate for `core`
  |
  = note: the `xtensa-esp32-espidf` target may not be installed
  = help: consider downloading the target with `rustup target add xtensa-esp32-espidf`

For more information about this error, try `rustc --explain E0463`.
error: could not compile `byteorder` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...

とのエラーを出力し,停止した.
その他,

error: toolchain '1.84.1-x86_64-unknown-linux-gnu' does not support target 'xtensa-esp32-espidf'
note: you can see a list of supported targets with `rustc --print=target-list`
note: if you are adding support for a new target to rustc itself, see https://rustc-dev-guide.rust-lang.org/building/new-target.html
data-layout for target `xtensa-esp32-espidf`, `e-m:e-p:32:32-v1:8:8-i64:64-i128:128-n32`, differs from LLVM target's `xtensa-none-elf` default layout, `e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32`

といったエラーに遭遇した.

調べる & 無限に Gemini に聞く

  • はっきり言うと Gemini はあまり参考にならなかった.教わった対処法をやっても無限ハマりします
  • エラー文で検索しまくる

このときの筆者::( Rust も最新だし nightly 使ってるのになんで動かんねん……)
このときの筆者2::( rustc --print=target-list の中にも入ってるしなんでホンマおい)

記事無限漁りをして全部試す

結局同じところでコケるので失敗から得られるものは少なかった

成功した後からの考察 ( Consideration )

Rust には,stable beta nightly という3つの channel がある.
今回の手法では,esp-rs が提供している esp channel の Rust
https://github.com/esp-rs/rust
を用いてビルドする必要があった.
^ (というふうに解釈している)
そのための toolchain channel のターゲティングのため +esp 指定が必要であった.

Discussion