背景:RustをビルドしていたUbuntuのPCにおいて、SDDを装換したため、素のUbuntuに戻ってしまい、ビルド環境がなくなった
課題:再度Rustビルド環境を構築する
結論:先人の手順を調べず場当たり的にエラー発生の都度対応、最終的にはビルドまでできた
詳細:
RISC-V用Rustビルド環境の構築手順は以下
curl https://sh.rustup.rs -sSf | sh source "$HOME/.cargo/env"
rustup toolchain install nightly --component rust-src
cargo install espup espup install . /home/<user_id>/export-esp.sh
cargo install cargo-espflash
cargo-espflashコマンドのインストール時エラーになった
warning: build failed, waiting for other jobs to finish... error: failed to compile `cargo-espflash v1.7.0`, intermediate artifacts can be found at `/tmp/cargo-installCYsweJ`
(確か前回もこのコマンドのインストールには失敗した記憶が)
代替えコマンドをインストールする
cargo install espflash
上記もエラーになった。これが使えないとFlashに焼けないのだが・・
ちょっと置いておく。
espmonitorをインストール
cargo install espmonitor
cargo install cargo-generate
これもエラーになった。openssh関連でパッケージが不足しているような印象だが。。
エラーメッセージで、pkg-configを入れてみて的な表記があったのでそれを試す
sudo apt install pkg-config
エラーは以下なので、opensslを入れないといけないのでは
No package 'openssl' found
エラー調査と解消
$ cargo install espflash error: failed to run custom build command for `libudev-sys v0.1.4`
ぐぐると、以下をやれと
Installing the libudev-dev package
上記パッケージを加えると通った。
sudo apt-get install libudev-dev cargo install espflash cargo install cargo-espflash
cargo-generateは、openssl-sys v0.9.87のカスタムビルドでエラー
cargo install cargo-generate error: failed to run custom build command for `openssl-sys v0.9.87`
ビルド途中のメッセージ(下記)より、
For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.
libssl-devを入れて再度ビルド。。通った
sudo apt-get install libssl-dev cargo install cargo-generate
build-essentialを入れろという記事もあったが、自分の環境ではすでに入っていた(詳細は参考URL)
buildできるかを確認
cargo generate --git https://github.com/esp-rs/esp-idf-template cargo
cargo build Compiling embassy-futures v0.1.0 The following warnings were emitted during compilation: warning: Configuring first supported MCU 'esp32c3' derived from the build target 'riscv32imc-esp-espidf' supporting MCUs [esp32c3, esp32c2, esp32h2, esp32c5]; explicitly specify an MCU to resolve this ambiguity error: failed to run custom build command for `esp-idf-sys v0.33.0`
やっぱりエラーが出た。なかなか一発では動かない・・
エラーメッセージの下の方には、git コマンドでエラーが出ているようで、、そもそもgitをまだ入れていなかったという。。
Caused by: 0: command '"git" "clone" "--recursive" "--depth" "1" "--shallow-submodules" "--branch" "release/v4.4" "https://github.com/espressif/esp-idf.git" "/home/sumi/lang/rust/helloworld/.embuild/espressif/esp-idf/release-v4.4"' failed to start 1: No such file or directory (os error 2)
gitを入れて再度実行・・・
sudo apt-get install git cargo build
またエラー、pipがないと怒られる。たしかに無い・・
/usr/bin/python3: No module named pip ERROR: Python interpreter at /usr/bin/python3 doesn't have pip installed. Please check the Getting Started Guides for the steps to install prerequisites for your OS. $ python3 -m pip /usr/bin/python3: No module named pip
pipを入れて再度実行
sudo apt-get install python3-pip cargo build
再度エラーでメッセージは以下
thread 'main' panicked at 'Unable to find libclang: "couldn't find any valid shared libraries matching: ['libclang.so', 'libclang-*.so', 'libclang.so.*', 'libclang-*.so.*'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])"',
ぐぐって、以下としてみろと・・ (LLVM入れていないな。。と思いつつ)
sudo apt-get install libclang-dev
再度エラー、stdbool.hがないと。 ググるとclang入れろと。
Caused by: clang diagnosed error: /home/<id>/<path>/rust/helloworld/.embuild/espressif/esp-idf/release-v4.4/components/esp_system/include/esp_system.h:19:10: fatal error: 'stdbool.h' file not found sudo apt install clang
install clangでLLVMも入ったようだ。
再度ビルドでエラー、
error: linker `ldproxy` not found
ldproxyを入れてなかった。
cargo install ldproxy cargo build
やっとビルドが通った。
怒られながら加えた追加パッケージは以下
- pkg-config
- libudev-dev
- libssl-dev
- git
- python3-pip
- libclang-dev
- clang
自主的に加えたのは以下
Rustボードに焼いて確認
espflash /dev/ttyACM0 $TARGET espflash /dev/ttyACM0 serial-monitor I (317) helloworld: Hello, world!
■インストール関連URL/参考URL
Other Installation Methods - Rust Forge
Setting Up a Development Environment - The Rust on ESP Book
Rustビルド中にfailed to run custom build command for openssl-sysエラー
GitHub - esp-rs/espressif-trainings: Embedded Rust on Espressif training material.