Rust on Ubuntu 22.04 in WSL2
はじめに_
WSL2上にUbuntuがインストールされているとする。
参考_
以下の記事に基づきインストールする。
Rustのインストール_
コンパイルに必要なソフトウェアをインストールする→build-essentialとは
% sudo apt install -y build-essential
Rust公式:はじめにに従いインストールする。
% curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ~中略~ Rust is installed now. Great! To get started you may need to restart your current shell. This would reload your PATH environment variable to include Cargo's bin directory ($HOME/.cargo/bin). To configure your current shell, run: source $HOME/.cargo/env % source $HOME/.cargo/env % which cargo /home/gotoh/.cargo/bin/cargo % which rustc /home/gotoh/.cargo/bin/rustc % rustc --version rustc 1.70.0 (90c541806 2023-05-31)
動作確認
% mkdir -p ~/Sandbox/Rust % cd ~/Sandbox/Rust % cargo new --bin prj_evid Created binary (application) `prj_evid` package % cd prj_evid/ % ls -1F Cargo.toml src/
ビルドする。
% cargo build Compiling prj_evid v0.1.0 (/home/gotoh/Sandbox/Rust/prj_evid) Finished dev [unoptimized + debuginfo] target(s) in 1.06s
実行する。
% cargo run Finished dev [unoptimized + debuginfo] target(s) in 0.00s Running `target/debug/prj_evid` Hello, world!
テストを実行する。
% cargo test Compiling prj_evid v0.1.0 (/home/gotoh/Sandbox/Rust/prj_evid) Finished test [unoptimized + debuginfo] target(s) in 0.29s Running unittests src/main.rs (target/debug/deps/prj_evid-fc89aa9c073b01cb) running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
VSCodeの設定_
VSCodeのインストール_
以下に従いインストールする。
拡張機能の設定_
VSCodeが起動中の場合は一度終了し、Ubuntu側から起動する。
% code .
原 旅人: コンセプトから理解するRustでおすすめされている、拡張機能をインストールする。
- rust-analyzer
- CodeLLDB
- Statusbar Error
また、rust-analayzerの設定でcargo check を cargo clippyに変更する。