1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SpacemacsでRustの開発環境を設定する

Posted at

はじめに

SpacemacsでRustの開発環境を構築したのですが、若干手間取りました。
そのためメモとして、構築方法を記載します。

注意点

エディタはSpacemacsを使用します。
単に最近使っているからという理由です。

手順

手順は大きく分けて、2つです。

  1. Rustの環境設定
  2. SpacemacsのRust layerの設定

Rustの環境設定

手順は下記の通りとなります。

  1. rustupのインストール
  2. racerのインストール
  3. cargo-editのインストール
  4. cargo-auditのインストール
  5. cargo-outdatedのインストール

rustup

下記を実行してください

curl https://sh.rustup.rs -sSf | sh
echo 'source $HOME/.cargo/env' >> 設定ファイルの場所(zshなら.zshrcなど)

racerのインストール

rustの最新をインストールしないと、コンパイルできないという罠があります。
下記を実行してください。

rustup install nightly
cargo +nightly install racer
rustup component add rust-src

racer complete std::io::B

Pathを設定ファイルに追加してください。(zshなら./zshrc等)

export "RUST_SRC_PATH=Rustのパス"

Rustのパスは大体下記となります。

ホームディレクトリ/.rustup/toolchains/rustのバージョン/lib/rustlib/src/rust/library/

cargo-editのインストール

cargo-editをインストールするには、open-sslとlibssl-devをインストールする必要があります。

open-sslのインストール

下記のコマンドを実行してください。

sudo dpkg -l | grep openssl

もしopensslの情報が表示されていなければ、下記でインストールしてください。

sudo apt install openssl

libssl-devのインストール

下記コマンドを実行してください。

sudo dpkg -l | grep libssl-dev

もしlibssl-devの情報が表示されなければ、下記でインストールしてください。

sudo apt install libssl-dev

cargo-editのインストール

下記コマンドを実行してください。

cargo install cargo-edit

cargo-auditのインストール

下記コマンドを実行してください。

cargo install cargo-audito

cargo-outdatedのインストール

下記コマンドを実行してください。

cargo install cargo-outdated

SpacemacsのRust layerの設定

dotspacemacs-configuration-layersに、rustと変数を記載してください。

dotspacemacs-configuration-layers
(
	省略
	rust
	(rust :variables rust-backend 'racer)

動作確認

下記コマンドを実行し、プロジェクトを作成してください。

cargo new --bin hello

Spacemacsでmainファイルを開けば、Rust layerで定義しているコマンドが実行できるはずです。

emacs -nw ./hello/src/main.rs

最後に

単純にSpacemacsを立ち上げるだけだと、Rust layerのコマンドを実行できないみたいです。
ここで一番時間がかかりました。
またJavaや.NET系と比べて意外と時間かかるな~と思いました。
(Javaや.NET系は統合開発環境をインストールすれば、よしなにしてくれるのですごい楽)

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?