プロジェクト

全般

プロフィール

Rust開発環境(Mac)

rustup

rustupのインストール

公式ドキュメントで推奨となっていたrustupをインストールします。
rustのツールチェーンを管理するパッケージです。
Homebrewを導入しているので、Homebrewからrustupをインストールします。

% brew install rustup-init
==> Downloading https://formulae.brew.sh/api/formula.jws.json
######################################################################### 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
######################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/rustup-init/manifests/1.26.0_1
######################################################################### 100.0%
==> Fetching rustup-init
==> Downloading https://ghcr.io/v2/homebrew/core/rustup-init/blobs/sha256:2f83c1
######################################################################### 100.0%
==> Pouring rustup-init--1.26.0_1.arm64_ventura.bottle.tar.gz
==> Caveats
Please run `rustup-init` to initialize `rustup` and install other Rust components.
==> Summary
🍺  /opt/homebrew/Cellar/rustup-init/1.26.0_1: 9 files, 6.6MB
==> Running `brew cleanup rustup-init`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

rustup-initの初回起動

rustup-initを起動すると、rustのツールチェインをどこにインストールするかの設定に関する表示と設定が走ります。
デフォルトでは、ユーザーのホームディレクトリ直下に .rustupおよび .cargoディレクトリを設けてその中にツールがインストールされます。

% rustup-init
Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  /Users/torutk/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /Users/torutk/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

  /Users/torutk/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /Users/torutk/.profile
  /Users/torutk/.zshenv

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:

   default host triple: aarch64-apple-darwin
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

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

1で続行すると、ツールをダウンロードしていきます。最後に次のメッセージが表示されます。


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" 

zshを実行すると、rustupコマンドが実行可能でした。上述のインストール時に、~/.zshenv ファイルが生成されていました。

```
. "$HOME/.cargo/env"
```

.zshenv ファイルは、zsh起動時に読み込まれるファイルとのことです。ログインシェル、コマンドラインからの
zsh実行時、シェルスクリプト実行時にも呼ばれるようです。

% rustup --version
rustup 1.26.0 (2023-04-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.73.0 (cc66ad468 2023-10-03)`

hello world

rustup環境でのhello worldを実施します。

work% cargo new hello_world               
     Created binary (application) `hello_world` package
work% ls
hello_world
work% cd hello_world       
hello_world % tree
.
├── Cargo.toml
└── src
    └── main.rs

2 directories, 2 files
hello_world % cat src/main.rs 
fn main() {
    println!("Hello, world!");
}

hello_world% cargo run            
   Compiling hello_world v0.1.0 (/Users/torutk/work/hello_world)
    Finished dev [unoptimized + debuginfo] target(s) in 1.08s
     Running `target/debug/hello_world`
Hello, world!
hello_world % 


6ヶ月前に更新