LoginSignup
0
1

More than 3 years have passed since last update.

Rustの環境構築及びHello World

Last updated at Posted at 2020-03-28

ずっと気になっていたRustの環境構築を行いました。

Macで環境構築及びHello World

curl https://sh.rustup.rs -sSf | shを実行

② デフォルトをインストールしたいので、下が表示されたらそのままenter

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

③ 下記のいずれかを~/.bash_profile~/.zsh_profileに追記

source $HOME/.cargo/env
# または($HOME/.cargo/envの中身が↓)
export PATH="$HOME/.cargo/bin:$PATH"

ちなみに最近のMacはデフォルトシェルがbashからzshになったらしいです。
僕はfishを使っているので~/.config/fish/config.fishに追記しました。

④ 以下を入力して保存

fn main() {
    println!("Hello, world!");
}

今回はhello_world.rsで保存しました。

rustc hello_world.rsでコンパイルし、./hello_worldで実行

Rust上でhello worldができました。

VSCodeの開発環境を整える

この拡張をインストール

② rustファイルを開くと、「Rustup not available」って怒られるので、vscodeのsetting.jsonのrust-client.rustupPathにrustupのpathを設定

{
  "rust-client.rustupPath": "/Users/USER/.cargo/bin/rustup"
}

③ 「RLS not installed.Install?」って聞かれるので、Yesをクリック。

これでVSCodeで補完ができるようになりました!

スクリーンショット 2020-03-28 16.49.14.png
(全くわからん😢)

最後に

とりあえず、Rustの最初の一歩が踏み出せました。
早くWebAssembly使った何かが作れるといいなぁ。

あと、Rustの日本語ドキュメントが本当に読みやすいです。
翻訳してくださった方、本当にありがとうございます😌

0
1
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
0
1