raspberrypi
Ubuntu Server をインストールした Raspberry Pi 4 に Rust 開発環境と WebAssembly 開発環境を整備する。
「実践Rustプログラミング入門」の「Chapter 6 WebAssembly」の内容を実行する。
https://www.shuwasystem.co.jp/book/9784798061702.html
Raspberry Pi 向け Ubuntu のページ
https://ubuntu.com/download/raspberry-pi
Ubuntu Server 20.04.1 LTS
Raspberry Pi 4 64-bit をインストール
インストールガイド
https://ubuntu.com/tutorials/how-to-install-ubuntu-on-your-raspberry-pi#1-overview
ヘッドレスでインストールするには system-boot/network-config
を編集してねと書いてあるが、うまくいかなかった。
Raspberry Pi OS と同様に wpa_supplicant.conf
を使って設定できた。
ssh で Raspberry Pi 4 にログインし、以下のコマンドを実行する。
途中で聞かれるインストール番号は default の 1 (1) Proceed with installation (default))
を入力する。
インストールが終了したら、source
でパスを通す。
バージョンを確認する。
VSCode の Remote - SSH
Extension を使って、Raspberry Pi 4 にログインしてセットアップした。
Rust 関連の Extension は rust-analyzer
、CodeLLDB
、Better TOML
をインストールした。
nvm、npm をインストールする。
cargo-generate のインストールに必要なパッケージをインストールした後、cargo-generate をインストールする。
cargo-generate でプロジェクトを作成する。
プロジェクト名を wasm_example
と入力する。
wasm のプロジェクトが作成される。
wasm-pack をインストールする。
Raspberry Pi 4 では install shell がエラーになってしまったので、
cargo install
でインストールしました。
https://rustwasm.github.io/wasm-pack/installer/#
wasm バイナリをビルドする。
以下のようなエラーが出た。
Cargo.toml
に、以下のオプションを記載する。
wasm_example/Cargo.toml
再度ビルドする。
pkg/wasm_example_bg.wasm
が作成されていれば OK 。
npm コマンドで Web アプリケーションを作成する。
localhost 以外からも参照できるように wasm_example/www/package.json
を編集する。
Web アプリケーションを実行する。
ブラウザから、http://<Raspberry Pi 4 の IP アドレス>:8080
にアクセスする。
「Hello, hello-wasm-pack!」が表示されれば成功。