Raspberry Pi に Rust をインストールする

最近では、C/C++ と同じくらい高速で、より安全なプログラミング言語として Rust が使われるようになってきています。そこで、Raspberry Pi にも Rust をインストールしていくことにします。

1. Rustのインストール

Rust の公式サイトにある手順でスクリプトを実行してインストールします。

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

表示される Current Installation options: では、1 を選択します。

Current installation options:


   default host triple: armv7-unknown-linux-gnueabihf
     default toolchain: stable
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1

~/.profile に以下のように PATH が追加されていますから、ログインし直します。

export PATH="$HOME/.cargo/bin:$PATH"

再度ログインすると、rustc と cargo を実行できます。

$ rustc --version
rustc 1.48.0 (7eac88abb 2020-11-16)
$ cargo --version
cargo 1.48.0 (65cbdd2dc 2020-10-14)

2. cargo-edit のインストール

cargo-edit をインストールして、cargo add などのコマンドが使えるようにしておきます。ここで、libssl-dev と pkg-config が必要になりますのでインストールしておきます。

$ sudo apt install -y libssl-dev pkg-config

準備ができましたから、cargo-edit をインストールします。

$ cargo install cargo-edit

3. cargo make のインストール

続けて cargo make をクローンしてインストールします。

$ git clone https://github.com/sagiegurari/cargo-make.git
$ cd cargo-make
$ cargo install --force cargo-make

4. Rust の更新

Rust は rustup コマンドを使って更新することができます。

$ rustup update

5. おまけ

Raspberry Pi を使って Rust でコンパイルしていて、下記のようなエラーが出る場合がありました。(64bit 環境ですから Linux/aarch64 の場合です)

    Compiling heim-host v0.0.11
error[E0308]: mismatched types
  --> /home/<ユーザー>/.cargo/registry/src/github.com-1ecc6299db9ec823/heim-host-0.0.11/src/sys/linux/users/other.rs:79:25
      |
 79 | session_id: entry.ut_session,
      | ^^^^^^^^^^^^^^^^ expected `i32`, found `i64`
error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: could not compile `heim-host`.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed

これは、heim-host-0.0.11 の other.rs に書かれている session_id: entry.ut_session にある ut_session の型が i32 でなければならないのに i64 として解釈されていることが原因です。
この対応として、heim-host-0.0.11 にある other.rs の entry.ut_session を次のように”as i32″ を追加しておきます。

$ cd ~/.cargo/registry/src/github.com-xxxxxxxx/heim-host-0.0.11/src/sys/linux/users
$ vi other.rs
        session_id: entry.ut_session as i32;
この記事をシェアする
  • URLをコピーしました!
  • URLをコピーしました!
目次