概要
macOSにRustをインストールしてHello Worldを実施するまでの作業記録です。
インストール
Rustのページには Using rustup (Recommended) とあり、
curlでスクリプトをダウンロードしてshで実行する方法が載っています。
https://www.rust-lang.org/tools/install
brewも用意されているようだったので、今回はこちらで実施します。
https://formulae.brew.sh/formula/rustup-init
% brew install rustup-init
次に rustup-init コマンドを実行します。
% rustup-init
...
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1 # デフォルト設定でインストール
...
To configure your current shell, run:
source $HOME/.cargo/env
指示に従って、シェルのinitファイルに追加
# .zlogin
source $HOME/.cargo/env
rustupがインストールされました。
% rustup -v
rustup 1.24.3 (2021-05-31)
The Rust toolchain installer
...
% which rustup
/Users/username/.cargo/bin/rustup
また、コンパイラのrustc、パッケージマネージャのcargo、もインストールされました。
% rustc --version
rustc 1.61.0 (fe5b13d68 2022-05-18)
% cargo --version
cargo 1.61.0 (a028ae42f 2022-04-29)
% which rustc
/Users/username/.cargo/bin/rustc
% which cargo
/Users/username/.cargo/bin/cargo
Hello World!
プロジェクトの初期化
% cd workdir
% cargo new hello_world
Created binary (application) `hello_world` package
次のようなRustプログラム(src/main.rs)が生成されています。
fn main() {
println!("Hello, world!");
}
実行してみます。
% cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `target/debug/hello_world`
Hello, world!
無事に Hello, world! が表示されました。