以下の内容はhttps://dk521123.hatenablog.com/entry/2023/04/22/234808より取得しました。


【Rust】Rust ~ 環境構築編 ~

■ はじめに

以前、仕事で、プログラム言語の話になって、
Go言語が次にやりたいって話をしたところ、
Rustの方がいいのでは?的な話になったので、
気になって本を借りてみたら、かなり良さそうなのでメモ。

(本当は、仕事で使う Scala を勉強しないといけないのだが、
できれば、こっちの方、やりたい、、、)

目次

【0】Rust
 1)クロスコンパイル
 2)パフォーマンスの良さ
 3)他言語との連携が用意
【1】環境構築
 1)Windows / 簡易版
 2)Windows / 以前やったやり方
 3)MacOS
【2】Hello world
【3】トラブルシュート
 1)エラー「unable to find executable for <your program>.exe」が表示

【0】Rust

* 以下の利点があるプログラム言語、、、
 => めちゃめちゃいいとこどりだと思った。。。

1)クロスコンパイル

* Windows/Linux/MacOS で使える
 => Javaなどと同じ。
 => でも最近の言語では別に珍しくはない。

2)パフォーマンスの良さ

* C++並みに早い
 => Java/Swift/Go より 2~3倍速い
 => Ruby/Python3 より 約30倍速い

理由

* 機械語にコンパイル
* GCがない(「所有権」という独自の概念により)
* 静的型付け
* ゼロコスト抽象化 (Zero-cost abstraction)

3)他言語との連携が用意

* 他言語関数インターフェイス(Foreign Function Interface; FFI)
説明
rustc Rustコンパイラ
rustup Rustインストーラ・アップデータ
cargo Rustパッケージマネージャ
rustdoc ドキュメント生成ツール(rustdoc)
rustfmt コーディングスタイル整形ツール

【1】環境構築

1)Windows / 簡易版

[1] Rustのインストール

[1] Rustのインストール

* 以下のサイトから、ダウンロードしてインストールする
 => 「1」「1」(※)と選んでいけば、
  Visual Studioが入って、いい感じで構築できる
 (ただし、5~6GBの空きが必要)

https://www.rust-lang.org/tools/install

1) Quick install via the Visual Studio Community installer
   (free for individuals, academic uses, and open source).
2) Manually install the prerequisites
   (for enterprise and advanced users).
3) Don't install the prerequisites
   (if you're targeting the GNU ABI).
>1 (「1」を選択)

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1 (「1」を選択)

2)Windows / 以前やったやり方

[1] Microsoft C++ Build Toolsのインストール
[2] Rust (rustup) のインストール
[3] Visual Studio Code(VSCode)のインストール
 3-1) 拡張機能「rust-analyzer」のインストール
 3-2) 拡張機能「CodeLLDB」のインストール

https://developer.mamezou-tech.com/blogs/2023/02/12/using-rust-01/

[1] Microsoft C++ Build Toolsのインストール

* 以下のサイトから、ダウンロードしてインストールする
 => 「C++によるデスクトップ開発」にチェックを付ける
 => [言語パック]タブを選択し[日本語][英語]にチェックを付ける
 => 「インストール」ボタン押下し終わったらOS再起動

https://visualstudio.microsoft.com/ja/visual-cpp-build-tools/

[2] Rust (rustup) のインストール

* 以下のサイトから、ダウンロードしてインストールする
 => 終わったら、コマンドプロンプトで
  「rustup -V」「cargo --version」し確認

https://www.rust-lang.org/tools/install
補足:rustup

* rustをアップデートする (「rustup update」)
* 「rustc (コンパイラ)」「cargo (パッケージマネージャ)」が同梱

[3] Visual Studio CodeVSCode)のインストール

* 以下の関連記事などを参考にインストールする

https://dk521123.hatenablog.com/entry/2019/10/20/230323

3-1) 拡張機能「rust-analyzer」のインストール

* VS Code を開き、拡張機能メニュー (Ctrl + Shift + X) で
 『rust-analyzer』を検索し、インストールする

https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer

3-2) 拡張機能「CodeLLDB」のインストール

* VS Code を開き、拡張機能メニュー (Ctrl + Shift + X) で
 『CodeLLDB』を検索し、インストールする

3)MacOS

# Step1: Install rustup
brew install rustup-init

# Step2: Install rust
rustup-init
1) Proceed with standard installation (default - just press enter)
2) Customize installation
3) Cancel installation
> 1 (を入力し、Enterキー押下)

# Step3: 確認
rustup --version

【2】Hello world

* 以下の関連記事を参照のこと

Rust ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2025/11/26/224648

【3】トラブルシュート

1)エラー「unable to find executable for .exe」が表示

 実行しようとしたら
エラー「unable to find executable for <your program>.exe」
が表示されてしまう

解決案

* .vscode/launch.json を以下のように
 「"program": "${workspaceFolder}/【プロジェクト名】/src/main"」
 とし、再実行

修正例

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "lldb",
      "request": "launch",
      "name": "Debug",
      "program": "${workspaceFolder}/first_rust_project/src/main",
      "args": [],
      "cwd": "${workspaceFolder}"
    }
  ]
}

参考文献

https://learn.microsoft.com/ja-jp/windows/dev-environment/rust/setup
https://developer.mamezou-tech.com/blogs/2023/02/12/using-rust-01/

関連記事

Rust ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2025/11/26/224648
Rust ~ cargoコマンド ~
https://dk521123.hatenablog.com/entry/2025/12/12/011304
Rust ~ コメント ~
https://dk521123.hatenablog.com/entry/2025/12/13/000224
Rust ~ 制御文 ~
https://dk521123.hatenablog.com/entry/2025/12/07/234508
Rust ~ 変数 / データ型 ~
https://dk521123.hatenablog.com/entry/2025/12/05/000647
Rust ~ 複合型 / コレクション ~
https://dk521123.hatenablog.com/entry/2025/12/06/004709
Rust ~ enum / 列挙型 ~
https://dk521123.hatenablog.com/entry/2025/12/03/000831
Rust ~ 保有権 ~
https://dk521123.hatenablog.com/entry/2023/05/04/213726
Rust ~ 関数 / クロージャ
https://dk521123.hatenablog.com/entry/2025/12/09/094909
Rust ~ mod ~
https://dk521123.hatenablog.com/entry/2025/11/29/221911
Rust ~ crate / module ~
https://dk521123.hatenablog.com/entry/2025/12/11/234320
Rust ~ struct/impl/trait ~
https://dk521123.hatenablog.com/entry/2025/11/30/222255
Rust ~ Option型 ~
https://dk521123.hatenablog.com/entry/2025/12/01/223443
Rust ~ Error handling(Result型 / ?演算子) ~
https://dk521123.hatenablog.com/entry/2025/12/02/000346
Rust ~ Axum / 入門編 ~
https://dk521123.hatenablog.com/entry/2023/09/02/224707
Rust ~ Axum / Docker ~
https://dk521123.hatenablog.com/entry/2025/12/08/220615
Rust ~ Axum / REST ~
https://dk521123.hatenablog.com/entry/2025/11/27/145159
Rust template engine ~ Askama / 入門編 ~
https://dk521123.hatenablog.com/entry/2025/12/04/000102
Visual Studio Code ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2019/10/20/230323
sqlparser-rs ~ SQL Parser for Rust ~
https://dk521123.hatenablog.com/entry/2023/06/12/000000




以上の内容はhttps://dk521123.hatenablog.com/entry/2023/04/22/234808より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14