rust

Rust 関連

Rust ロゴ
Rust (ラスト) は、性能、メモリ安全性、安全な並行性を目指して設計されたマルチパラダイムのプログラミング言語である。C 言語、C++ に代わるシステムプログラミング言語を目指しており、構文的にはC++に似ているが、「ボローチェッカー」(borrow checker) で参照の有効性を検証することによってメモリ安全性を保証できる。Rust はガベージコレクションなしでのメモリ安全性を達成しており、必要な場面で参照カウントを使うこともできる。
出典: Rust (プログラミング言語) - Wikiwand

本家: Rustプログラミング言語 - rust-lang.org
  Rust の日本語情報 - rust-jp.rs
ソースコード: The Rust Programming Language 翻訳
       GitHub - rust-lang/rust: Empowering everyone to build reliable and efficient software.
ドキュメント: The Rust Programming Language - The Rust Programming Language 翻訳 (公式英語) - rust-lang.org
       Rustを学ぶ/Rustプログラミング言語 - rust-lang.org
       Rustの日本語ドキュメント/Japanese Docs for Rust - rust-jp.rs
       The Rust Programming Language 日本語版 - The Rust Programming Language 日本語版 (日本語訳) - rust-jp.rs
       The Rust Programming Language 日本語版 (PDF版) (日本語訳) - rust-jp.rs
       Introduction - Rust By Example 日本語版 - rust-jp.rs
       Introduction - Rust By Example - rust-lang.org
その他: Introduction - The Rust RFC Book 翻訳

Fedora (Rust 公式から...)

公式(非公式日本語翻訳): インストール - The Rust Programming Language 日本語版 より
cargorustc、および、rustupなどもインストールされる😃

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

info: downloading installer

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:

  /home/tomoyan/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /home/tomoyan/.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:

  /home/tomoyan/.cargo/bin

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

  /home/tomoyan/.profile
  /home/tomoyan/.bash_profile
  /home/tomoyan/.bashrc

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

Current installation options:


   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
> Enter で続行

info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2023-03-28, rust version 1.68.2 (9eb3afe9e 2023-03-27)
info: downloading component 'cargo'
  6.7 MiB /   6.7 MiB (100 %)   2.2 MiB/s in  3s ETA:  0s
info: downloading component 'clippy'
  2.4 MiB /   2.4 MiB (100 %) 951.7 KiB/s in  2s ETA:  0s
info: downloading component 'rust-docs'
 19.5 MiB /  19.5 MiB (100 %)   4.0 MiB/s in  4s ETA:  0s
info: downloading component 'rust-std'
 29.9 MiB /  29.9 MiB (100 %)   4.9 MiB/s in  6s ETA:  0s
info: downloading component 'rustc'
 68.1 MiB /  68.1 MiB (100 %)   4.3 MiB/s in 15s ETA:  0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 19.5 MiB /  19.5 MiB (100 %)   5.5 MiB/s in  3s ETA:  0s
info: installing component 'rust-std'
 29.9 MiB /  29.9 MiB (100 %)   7.3 MiB/s in  4s ETA:  0s
info: installing component 'rustc'
 68.1 MiB /  68.1 MiB (100 %)   9.1 MiB/s in  7s ETA:  0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu installed - rustc 1.68.2 (9eb3afe9e 2023-03-27)


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"

warning: it looks like you have an existing installation of Rust at:
warning: /usr/bin
warning: rustup should not be installed alongside Rust. Please uninstall your existing Rust first.
warning: Otherwise you may have confusion unless you are careful with your PATH
warning: If you are sure that you want both rustup and your already installed Rust
warning: then please reply `y' or `yes' or set RUSTUP_INIT_SKIP_PATH_CHECK to yes
warning: or pass `-y' to ignore all ignorable checks.
Rust の既存のインストールがあるようです:
/usr/bin
rustup は Rust と一緒にインストールしないでください。最初に既存の Rust をアンインストールしてください。
そうしないと、PATH に注意しない限り、混乱する可能性があります。
rustup とすでにインストールされているRustの両方が必要な場合は、`y' または `yes' と応答するか、RUSTUP_INIT_SKIP_PATH_CHECK を yes に設定するか、`-y' を渡してすべてのチェックを無視できます。
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:

  /home/tomoyan/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory located at:

  /home/tomoyan/.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:

  /home/tomoyan/.cargo/bin

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

  /home/tomoyan/.profile
  /home/tomoyan/.bash_profile
  /home/tomoyan/.bashrc

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.
Rust へようこそ!

これにより、Rust プログラミング言語の公式コンパイラとそのパッケージマネージャーである Cargo がダウンロードおよびインストールされます。

Rustupメタデータとツールチェーンは、次の場所にあるRustupホームディレクトリにインストールされます。

  /home/tomoyan/.rustup

これは、RUSTUP_HOME 環境変数を使用して変更できます。

次の場所にある Cargo ホームディレクトリ:

  /home/tomoyan/.cargo

これは、CARGO_HOME 環境変数を使用して変更できます。

cargo、rustc、rustup、およびその他のコマンドは、次の場所にある Cargo の bin ディレクトリに追加されます。

  /home/tomoyan/.cargo/bin

このパスは、次の場所にあるプロファイルファイルを変更することにより、PATH 環境変数に追加されます。

  /home/tomoyan/.profile
  /home/tomoyan/.bash_profile
  /home/tomoyan/.bashrc

rustup セルフアンインストールを使用すると、いつでもアンインストールでき、これらの変更は元に戻されます。

.bashrc に自動ロードの設定を追加する。

$ echo 'source $HOME/.cargo/env' >> ~/.bashrc


bash の設定を反映させる。

$ . ~/.bashrc


動作確認

$ rustup --version

rustup 1.25.2 (17db695f1 2023-02-01)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.68.2 (9eb3afe9e 2023-03-27)`

$ rustc --version

rustc 1.68.2 (9eb3afe9e 2023-03-27)

$ cargo --version

cargo 1.68.2 (6feb7c9cf 2023-03-26)

実行ファイルのパス確認

$ which rustup rustc cargo

~/.cargo/bin/rustup
~/.cargo/bin/rustc
~/.cargo/bin/cargo

こちらは Fedora のリポジトリからインストールしたコマンドである🤔

$ /bin/rustc --version && /bin/cargo --version

rustc 1.63.0 (Fedora 1.63.0-1.fc36)
cargo 1.63.0

Fedora (RPM パッケージから...)

この手順はスキップして構わない。Rust 公式からのインストールで開発環境は整う🤔
cargorustc はインストールされるが、rustup が存在しない…🤔

$ sudo dnf install rust cargo

メタデータの期限切れの最終確認: 4:36:48 時間前の 2022年08月31日 22時35分04秒 に実施しました。
依存関係が解決しました。
==============================================================================================================
 パッケージ                    アーキテクチャー     バージョン                    リポジトリー          サイズ
==============================================================================================================
インストール:
 cargo                         x86_64               1.63.0-1.fc36                 updates               4.6 M
 rust                          x86_64               1.63.0-1.fc36                 updates                25 M
依存関係のインストール:
 rust-std-static               x86_64               1.63.0-1.fc36                 updates                27 M

トランザクションの概要
==============================================================================================================
インストール  3 パッケージ

ダウンロードサイズの合計: 56 M
インストール後のサイズ: 220 M
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
(1/3): cargo-1.63.0-1.fc36.x86_64.rpm                                         3.7 MB/s | 4.6 MB     00:01    
(2/3): rust-std-static-1.63.0-1.fc36.x86_64.rpm                               2.7 MB/s |  27 MB     00:09    
(3/3): rust-1.63.0-1.fc36.x86_64.rpm                                          1.7 MB/s |  25 MB     00:14    
--------------------------------------------------------------------------------------------------------------
合計                                                                          3.4 MB/s |  56 MB     00:16     
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                                                      1/1 
  インストール中   : rust-std-static-1.63.0-1.fc36.x86_64                                                 1/3 
  インストール中   : rust-1.63.0-1.fc36.x86_64                                                            2/3 
  インストール中   : cargo-1.63.0-1.fc36.x86_64                                                           3/3 
  scriptletの実行中: cargo-1.63.0-1.fc36.x86_64                                                           3/3 
  検証             : cargo-1.63.0-1.fc36.x86_64                                                           1/3 
  検証             : rust-1.63.0-1.fc36.x86_64                                                            2/3 
  検証             : rust-std-static-1.63.0-1.fc36.x86_64                                                 3/3 

インストール済み:
  cargo-1.63.0-1.fc36.x86_64       rust-1.63.0-1.fc36.x86_64       rust-std-static-1.63.0-1.fc36.x86_64      

完了しました!

動作確認

$ rustc --version

rustc 1.63.0 (Fedora 1.63.0-1.fc36)

$ cargo --version

cargo 1.63.0

DietPi (Raspberry Pi Zero WH)

公式: Installation - The Rust Programming Language 翻訳
非公式日本語: インストール - The Rust Programming Language 日本語版

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

info: downloading installer

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:

  /home/dietpi/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /home/dietpi/.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:

  /home/dietpi/.cargo/bin

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

  /home/dietpi/.profile
  /home/dietpi/.bashrc

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

Current installation options:


   default host triple: arm-unknown-linux-gnueabihf
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
> -> Enter を入力

info: profile set to 'default'
info: default host triple is arm-unknown-linux-gnueabihf
info: syncing channel updates for 'stable-arm-unknown-linux-gnueabihf'
info: latest update on 2023-08-03, rust version 1.71.1 (eb26296b5 2023-08-03)
info: downloading component 'cargo'
  6.5 MiB /   6.5 MiB (100 %) 609.6 KiB/s in 10s ETA:  0s
info: downloading component 'clippy'
  2.2 MiB /   2.2 MiB (100 %) 444.4 KiB/s in  6s ETA:  0s
info: downloading component 'rust-docs'
 13.6 MiB /  13.6 MiB (100 %) 552.9 KiB/s in 29s ETA:  0s
info: downloading component 'rust-std'
 23.0 MiB /  23.0 MiB (100 %) 424.2 KiB/s in 50s ETA:  0s
info: downloading component 'rustc'
 73.0 MiB /  73.0 MiB (100 %) 443.7 KiB/s in  2m  9s ETA:  0s    
info: downloading component 'rustfmt'
  2.1 MiB /   2.1 MiB (100 %) 490.6 KiB/s in  4s ETA:  0s
info: installing component 'cargo'
  6.5 MiB /   6.5 MiB (100 %)   1.5 MiB/s in  4s ETA:  0s
info: installing component 'clippy'
  2.2 MiB /   2.2 MiB (100 %)   1.6 MiB/s in  2s ETA:  0s
info: installing component 'rust-docs'
 13.6 MiB /  13.6 MiB (100 %) 398.4 KiB/s in  1m 19s ETA:  0s
info: installing component 'rust-std'
 23.0 MiB /  23.0 MiB (100 %)   1.5 MiB/s in 23s ETA:  0s
info: installing component 'rustc'
 73.0 MiB /  73.0 MiB (100 %) 940.8 KiB/s in 58s ETA:  0s
info: installing component 'rustfmt'
  2.1 MiB /   2.1 MiB (100 %)   1.6 MiB/s in  2s ETA:  0s
info: default toolchain set to 'stable-arm-unknown-linux-gnueabihf'

  stable-arm-unknown-linux-gnueabihf installed - rustc 1.71.1 (eb26296b5 2023-08-03)


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"

$HOME/.cargo/env
#!/bin/sh
# rustup shell setup
# affix colons on either side of $PATH to simplify matching
case ":${PATH}:" in
    *:"$HOME/.cargo/bin":*)
        ;;
    *)
        # Prepending path in case a system-installed rustc needs to be overridden
        export PATH="$HOME/.cargo/bin:$PATH"
        ;;
esac

.profile に自動ロードの設定を追加する。

$ echo 'source $HOME/.cargo/env' >> ~/.profile

動作確認

$ rustc --version

rustc 1.61.0 (fe5b13d68 2022-05-18)

$ cargo --version

cargo 1.61.0 (a028ae42f 2022-04-29)

~/.cargo/bin/ の内容🤔

$ ls -l ~/.cargo/bin/

total 181136
-rwxr-xr-x 12 dietpi dietpi 13974212 Jun  8 08:49 cargo
-rwxr-xr-x 12 dietpi dietpi 13974212 Jun  8 08:49 cargo-clippy
-rwxr-xr-x 12 dietpi dietpi 13974212 Jun  8 08:49 cargo-fmt
-rwxr-xr-x 12 dietpi dietpi 13974212 Jun  8 08:49 cargo-miri
-rwxr-xr-x 12 dietpi dietpi 13974212 Jun  8 08:49 clippy-driver
-rwxr-xr-x 12 dietpi dietpi 13974212 Jun  8 08:49 rls
-rwxr-xr-x 12 dietpi dietpi 13974212 Jun  8 08:49 rust-gdb
-rwxr-xr-x 12 dietpi dietpi 13974212 Jun  8 08:49 rust-lldb
-rwxr-xr-x 12 dietpi dietpi 13974212 Jun  8 08:49 rustc
-rwxr-xr-x 12 dietpi dietpi 13974212 Jun  8 08:49 rustdoc
-rwxr-xr-x 12 dietpi dietpi 13974212 Jun  8 08:49 rustfmt
-rwxr-xr-x 12 dietpi dietpi 13974212 Jun  8 08:49 rustup
-rwxr-xr-x  1 dietpi dietpi 17775060 Jun 16 19:34 sccache

Visual Studio、Visual Studio Code を利用する場合は Windows で Rust 用の開発環境を設定する も参照。

以下は Scoop によるインストール手順です🤔

$ scoop install rustup

Installing 'rustup' (1.26.0) [64bit] from main bucket
rustup-init.exe (8.2 MB) [====================================================================================] 100%
Checking hash of rustup-init.exe ... ok.
Running installer script...
Linking ~\scoop\apps\rustup\current => ~\scoop\apps\rustup\1.26.0
Persisting .cargo
Persisting .rustup
'rustup' (1.26.0) was installed successfully!
Notes
-----
This package defaults to using the MSVC toolchain in new installs; use "rustup set default-host" to configure it
(existing installs may be using the GNU toolchain by default)
According to https://doc.rust-lang.org/book/ch01-01-installation.html#installing-rustup-on-windows
Microsoft C++ Build Tools is needed and can be downloaded here:
https://visualstudio.microsoft.com/visual-cpp-build-tools/
When installing build tools, these two components should be selected:
- MSVC - VS C++ x64/x86 build tools
- Windows SDK

Notes
-----
This package defaults to using the MSVC toolchain in new installs; use "rustup set default-host" to configure it
(existing installs may be using the GNU toolchain by default)
According to https://doc.rust-lang.org/book/ch01-01-installation.html#installing-rustup-on-windows
Microsoft C++ Build Tools is needed and can be downloaded here:
https://visualstudio.microsoft.com/visual-cpp-build-tools/
When installing build tools, these two components should be selected:
- MSVC - VS C++ x64/x86 build tools
- Windows SDK
ノート
-----
このパッケージは、新規インストールではデフォルトで MSVC ツールチェーンを使用します。 "rustup set default-host" を使用して設定します
(既存のインストールではデフォルトで GNU ツールチェーンが使用されている可能性があります)
https://doc.rust-lang.org/book/ch01-01-installation.html#installing-rustup-on-windows によると
Microsoft C++ Build Tools が必要で、ここからダウンロードできます:
https://visualstudio.microsoft.com/visual-cpp-build-tools/
ビルド ツールをインストールするときは、次の 2 つのコンポーネントを選択する必要があります:
- MSVC - VS C++ x64/x86 build tools
- Windows SDK
To get started you need Cargo's bin directory (C:\Users\tomoyan\scoop\persist
\rustup\.cargo\bin) in your PATH
environment variable. This has not been done automatically.
開始するには、PATH 環境変数に Cargo の bin ディレクトリ (C:\Users\tomoyan\scoop\persist\rustup\.cargo\bin) が必要です。
これは自動的には行われません。
Notes
-----
To use the MSVC ABI without Visual Studio 2015 (or higher) installed, you will need the Visual Studio 2017 Build Tools:
https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017
Visual Studio 2015 (またはそれ以降) をインストールせずにMSVC ABIを使用するには、Visual Studio 2017ビルドツールが必要です。
https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017

環境変数の設定

$ cat ~\scoop\buckets\main\bucket\rustup.json

{
    "version": "1.26.0",
    "description": "Manage multiple rust installations with ease",
    "homepage": "https://rustup.rs",
    "license": "MIT|Apache-2.0",
    "notes": [
        "This package defaults to using the MSVC toolchain in new installs; use \"rustup set default-host\" to configure it",
        "(existing installs may be using the GNU toolchain by default)",
        "According to https://doc.rust-lang.org/book/ch01-01-installation.html#installing-rustup-on-windows",
        "Microsoft C++ Build Tools is needed and can be downloaded here: https://visualstudio.microsoft.com/visual-cpp-build-tools/",
        "When installing build tools, these two components should be selected:",
        "- MSVC - VS C++ x64/x86 build tools",
        "- Windows SDK"
    ],
    "architecture": {
        "64bit": {
            "url": "https://static.rust-lang.org/rustup/archive/1.26.0/x86_64-pc-windows-msvc/rustup-init.exe",
            "hash": "365d072ac4ef47f8774f4d2094108035e2291a0073702db25fa7797a30861fc9"
        },
        "32bit": {
            "url": "https://static.rust-lang.org/rustup/archive/1.26.0/i686-pc-windows-msvc/rustup-init.exe",
            "hash": "3fcfaf0018c12b96c49dc7e13e8638bd8de686ab27dd14238c3f11d0a936c003"
        }
    },
    "installer": {
        "script": [
            "[Environment]::SetEnvironmentVariable('CARGO_HOME', \"$persist_dir\\.cargo\", 'Process')",
            "[Environment]::SetEnvironmentVariable('RUSTUP_HOME', \"$persist_dir\\.rustup\", 'Process')",
            "Invoke-ExternalCommand -Path \"$dir\\rustup-init.exe\" -Args @('-y', '--no-modify-path') | Out-Null"
        ]
    },
    "env_add_path": ".cargo\\bin",
    "env_set": {
        "CARGO_HOME": "$persist_dir\\.cargo",
        "RUSTUP_HOME": "$persist_dir\\.rustup"
    },
    "persist": [
        ".cargo",
        ".rustup"
    ],
    "checkver": {
        "url": "https://raw.githubusercontent.com/rust-lang-nursery/rustup.rs/master/Cargo.toml",
        "regex": "version = \"([\\d.]+)\""
    },
    "autoupdate": {
        "architecture": {
            "64bit": {
                "url": "https://static.rust-lang.org/rustup/archive/$version/x86_64-pc-windows-msvc/rustup-init.exe"
            },
            "32bit": {
                "url": "https://static.rust-lang.org/rustup/archive/$version/i686-pc-windows-msvc/rustup-init.exe"
            }
        },
        "hash": {
            "url": "$url.sha256"
        }
    }
}

インストーラはレジストリのPath 環境変数を自動で設定していないので、PowerShell を再起動すると消える🤔
PowerShell を終了する前にレジストリのユーザー環境変数に Path を設定するには以下のコマンドを実行する😉

$ [Environment]::SetEnvironmentVariable('Path', $env:CARGO_HOME + '\bin;' + $env:Path, 'User')


動作確認

$ rustc --version

rustc 1.71.0 (8ede3aae2 2023-07-12)

$ cargo --version

cargo 1.71.0 (cfd3bbd8f 2023-06-08)

Can not install on android - target 'aarch64-linux-android' not found in channel. · Issue #2872 · rust-lang/rustup🤔
TermuxArch/TermuxArch: Experience the pleasure of the Linux command prompt in Android, Chromebook, Fire OS and Windows on smartphone, smartTV, tablet and wearable https://termuxarch.github.io/TermuxArch/ を参照🤔
TermuxArch で rustup を使用するとのことですが試せてません😅

Welcome to Termux!

Wiki:            https://wiki.termux.com
Community forum: https://termux.com/community
Gitter chat:     https://gitter.im/termux/termux
IRC channel:     #termux on freenode

Working with packages:

 * Search packages:   pkg search 
 * Install a package: pkg install 
 * Upgrade packages:  pkg upgrade

Subscribing to additional repositories:

 * Root:     pkg install root-repo
 * Unstable: pkg install unstable-repo
 * X11:      pkg install x11-repo

Report issues at https://termux.com/issues

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

info: downloading installer
error: $HOME differs from euid-obtained home directory: you may be using sudo
error: $HOME directory: /data/data/com.termux/files/home
error: euid-obtained home directory: /data
error: if this is what you want, restart the installation with `-y'

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:

  /data/data/com.termux/files/home/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /data/data/com.termux/files/home/.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:

  /data/data/com.termux/files/home/.cargo/bin

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

  /data/data/com.termux/files/home/.profile
  /data/data/com.termux/files/home/.bashrc

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

Current installation options:


   default host triple: aarch64-linux-android
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

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

info: profile set to 'default'
info: default host triple is aarch64-linux-android
info: syncing channel updates for 'stable-aarch64-linux-android'
info: latest update on 2022-08-11, rust version 1.63.0 (4b91a6ea7 2022-08-08)
error: target 'aarch64-linux-android' not found in channel.  Perhaps check https://doc.rust-lang.org/nightly/rustc/platform-support.html for available targets
$

参考: Hello, World! - The Rust Programming Language 日本語版

$ mkdir -p rs_projects/hello_world


$ cd rs_projects/hello_world


$ cat << EOF > main.rs
fn main() {
    // ようこそ、はるおわ〜るどへ!
    println!("Welcome to Haruo World!🤤");
}
EOF


$ rustc main.rs
$ ./main

Welcome to Haruo World!🤤

参考: Hello, Cargo! - The Rust Programming Language 日本語版

Cargo のバージョンが表示されれば利用出来る状態になっていることが確認できる🤔

$ cargo --version

cargo 1.71.1 (7f1d04c00 2023-07-29)

Cargo でアプリ haruo_cargo パッケージを作成する🤔 (雛形が生成される)

$ cargo new haruo_cargo

     Created binary (application) `haruo_cargo` package

$ cd haruo_cargo/
$ ll

合計 4
-rw-r--r-- 1 tomoyan tomoyan 180 12月  6 09:00 Cargo.toml
drwxr-xr-x 1 tomoyan tomoyan  14 12月  6 09:00 src

$ cat Cargo.toml

[package]
name = "haruo_cargo"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

$ cat src/main.rs

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

$ sed -i -e 's/Hello/Haruo/g' src/main.rs

$ cargo run

   Compiling haruo_cargo v0.1.0 (/home/dietpi/my_projects/haruo_cargo)
    Finished dev [unoptimized + debuginfo] target(s) in 7.36s
     Running `target/debug/haruo_cargo`
Haruo, world!

公式: G - How Rust is Made and “Nightly Rust” - The Rust Programming Language (英語)
 付録G:Rustの作られ方と“Nightly Rust” - The Rust Programming Language 日本語版 より
6週間サイクルで新しいバージョンの Rust が準備されるので、リリース情報を確認して適時更新する😉

公式: Current Release Versions - Rust Forge でリリースを確認できる🤔

rustup の更新を行う🤔

$ rustup self update
info: checking for self-update
info: downloading self-update
  rustup updated - 1.27.0 (from 1.26.0)

$ rustup -V

rustup 1.27.0 (bbb9276d2 2024-03-08)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.74.1 (a28077b28 2023-12-04)

rust の更新を行う🤔

$ rustup update

info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2024-03-21, rust version 1.77.0 (aedd173a2 2024-03-17)
info: downloading component 'rust-std' for 'thumbv6m-none-eabi'
  9.1 MiB /   9.1 MiB (100 %)   3.2 MiB/s in  2s ETA:  0s
info: downloading component 'rust-std' for 'arm-unknown-linux-gnueabihf'
 21.0 MiB /  21.0 MiB (100 %)   2.3 MiB/s in  8s ETA:  0s
info: downloading component 'rust-src'
  2.5 MiB /   2.5 MiB (100 %)   2.2 MiB/s in  1s ETA:  0s
info: downloading component 'cargo'
  8.0 MiB /   8.0 MiB (100 %)   1.3 MiB/s in  6s ETA:  0s
info: downloading component 'clippy'
info: downloading component 'rust-docs'
 14.9 MiB /  14.9 MiB (100 %)   1.7 MiB/s in 10s ETA:  0s
info: downloading component 'rust-std'
 26.6 MiB /  26.6 MiB (100 %)   2.2 MiB/s in 17s ETA:  0s
info: downloading component 'rustc'
 60.3 MiB /  60.3 MiB (100 %)   3.1 MiB/s in 26s ETA:  0s
info: downloading component 'rustfmt'
info: removing previous version of component 'rust-std' for 'thumbv6m-none-eabi'
info: removing previous version of component 'rust-std' for 'arm-unknown-linux-gnueabihf'
info: removing previous version of component 'rust-src'
info: removing previous version of component 'cargo'
info: removing previous version of component 'clippy'
info: removing previous version of component 'rust-docs'
info: removing previous version of component 'rust-std'
info: removing previous version of component 'rustc'
info: removing previous version of component 'rustfmt'
info: installing component 'rust-std' for 'thumbv6m-none-eabi'
  9.1 MiB /   9.1 MiB (100 %)   8.3 MiB/s in  2s ETA:  0s
info: installing component 'rust-std' for 'arm-unknown-linux-gnueabihf'
 21.0 MiB /  21.0 MiB (100 %)   8.1 MiB/s in  2s ETA:  0s
info: installing component 'rust-src'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 14.9 MiB /  14.9 MiB (100 %)   3.7 MiB/s in  4s ETA:  0s
info: installing component 'rust-std'
 26.6 MiB /  26.6 MiB (100 %)   6.5 MiB/s in  4s ETA:  0s
info: installing component 'rustc'
 60.3 MiB /  60.3 MiB (100 %)   5.6 MiB/s in 10s ETA:  0s
info: installing component 'rustfmt'
info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
756.5 KiB / 756.5 KiB (100 %) 327.7 KiB/s in  3s ETA:  0s
info: latest update on 2024-03-25, rust version 1.79.0-nightly (0824b300e 2024-03-24)
info: downloading component 'rust-src'
  2.5 MiB /   2.5 MiB (100 %) 515.1 KiB/s in  6s ETA:  0s
info: downloading component 'rust-std' for 'riscv32imac-unknown-none-elf'
  9.2 MiB /   9.2 MiB (100 %)   2.2 MiB/s in  4s ETA:  0s
info: downloading component 'rust-std' for 'riscv32imc-unknown-none-elf'
  9.0 MiB /   9.0 MiB (100 %)   3.9 MiB/s in  9s ETA:  0s
info: downloading component 'llvm-tools'
 31.3 MiB /  31.3 MiB (100 %) 690.1 KiB/s in  2m 43s ETA:  0s    
info: downloading component 'cargo'
  8.1 MiB /   8.1 MiB (100 %)   3.6 MiB/s in  2s ETA:  0s
info: downloading component 'rust-std'
 26.3 MiB /  26.3 MiB (100 %)   4.4 MiB/s in  6s ETA:  0s
info: downloading component 'rustc'
 64.8 MiB /  64.8 MiB (100 %)   4.2 MiB/s in 20s ETA:  0s
info: removing previous version of component 'rust-src'
info: removing previous version of component 'rust-std' for 'riscv32imac-unknown-none-elf'
info: removing previous version of component 'rust-std' for 'riscv32imc-unknown-none-elf'
info: removing previous version of component 'llvm-tools'
info: removing previous version of component 'cargo'
info: removing previous version of component 'rust-std'
info: removing previous version of component 'rustc'
info: installing component 'rust-src'
info: installing component 'rust-std' for 'riscv32imac-unknown-none-elf'
  9.2 MiB /   9.2 MiB (100 %)   8.5 MiB/s in  1s ETA:  0s
info: installing component 'rust-std' for 'riscv32imc-unknown-none-elf'
  9.0 MiB /   9.0 MiB (100 %)   8.5 MiB/s in  1s ETA:  0s
info: installing component 'llvm-tools'
 31.3 MiB /  31.3 MiB (100 %)   9.2 MiB/s in  3s ETA:  0s
info: installing component 'cargo'
info: installing component 'rust-std'
 26.3 MiB /  26.3 MiB (100 %)   8.5 MiB/s in  3s ETA:  0s
info: installing component 'rustc'
 64.8 MiB /  64.8 MiB (100 %)   7.3 MiB/s in  8s ETA:  0s
info: checking for self-update

   stable-x86_64-unknown-linux-gnu updated - rustc 1.77.0 (aedd173a2 2024-03-17) (from rustc 1.74.1 (a28077b28 2023-12-04))
  nightly-x86_64-unknown-linux-gnu updated - rustc 1.79.0-nightly (0824b300e 2024-03-24) (from (timeout reading rustc version))

info: cleaning up downloads & tmp directories

公式: Toolchains - The rustup book 翻訳
Rust のツールチェーン仕様は

<channel>[-<date>][-<host>]

<channel>       = stable|beta|nightly|<major.minor>|<major.minor.patch>
<date>          = YYYY-MM-DD
<host>          = <target-triple>
例: stable-x86_64-unknown-linux-gnu
channel: stable
date:
host: x86_64-unknown-linux-gnu (target-triple)

esp32 マイコン用の esp ツールチェーンは espup で追加する。

インストール済みのツールチェーン一覧の確認🤔

$ rustup toolchain list

stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
esp

デフォルトのツールチェインを確認する🤔
Fedora

$ rustup show

Default host: x86_64-unknown-linux-gnu
rustup home:  /home/tomoyan/.rustup

stable-x86_64-unknown-linux-gnu (default)
rustc 1.72.0 (5680fa18f 2023-08-23)

DietPi

$ rustup show

Default host: arm-unknown-linux-gnueabihf
rustup home:  /home/dietpi/.rustup

stable-arm-unknown-linux-gnueabihf (default)
rustc 1.72.0 (5680fa18f 2023-08-23)

公式: Channels - The rustup book 翻訳

$ rustup toolchain install 1.67

info: syncing channel updates for '1.67-x86_64-unknown-linux-gnu'
info: latest update on 2023-02-09, rust version 1.67.1 (d5a82bbd2 2023-02-07)
info: downloading component 'cargo'
  6.6 MiB /   6.6 MiB (100 %)   2.7 MiB/s in  2s ETA:  0s
info: downloading component 'clippy'
info: downloading component 'rust-docs'
 19.3 MiB /  19.3 MiB (100 %)   3.8 MiB/s in  5s ETA:  0s
info: downloading component 'rust-std'
 29.3 MiB /  29.3 MiB (100 %) 522.0 KiB/s in 15s ETA:  0s
info: downloading component 'rustc'
 67.8 MiB /  67.8 MiB (100 %)   4.5 MiB/s in 18s ETA:  0s
info: downloading component 'rustfmt'
  4.5 MiB /   4.5 MiB (100 %)   4.1 MiB/s in  1s ETA:  0s
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 19.3 MiB /  19.3 MiB (100 %)   5.0 MiB/s in  3s ETA:  0s
info: installing component 'rust-std'
 29.3 MiB /  29.3 MiB (100 %)   6.9 MiB/s in  4s ETA:  0s
info: installing component 'rustc'
 67.8 MiB /  67.8 MiB (100 %)   6.3 MiB/s in 16s ETA:  0s
  4 IO-ops /   4 IO-ops (100 %)   0 IOPS in  8s ETA: Unknown
info: installing component 'rustfmt'

  1.67-x86_64-unknown-linux-gnu installed - rustc 1.67.1 (d5a82bbd2 2023-02-07)

info: checking for self-update

追加されたツールチェーンのコンパイラバージョンを確認する🤔

$ rustup run 1.67 rustc -V

rustc 1.67.1 (d5a82bbd2 2023-02-07)

追加されたツールチェーンをデフォルトに設定する🤔

$ rustup default 1.67

info: using existing install for '1.67-x86_64-unknown-linux-gnu'
info: default toolchain set to '1.67-x86_64-unknown-linux-gnu'

  1.67-x86_64-unknown-linux-gnu unchanged - rustc 1.67.1 (d5a82bbd2 2023-02-07)

ツールチェーン一覧でもデフォルトを確認できる🤔

$ rustup toolchain list

stable-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu
1.67-x86_64-unknown-linux-gnu (default)
esp

デフォルトツールチェーンのコンパイラバージョンを確認する🤔

$ rustc -V --verbose

rustc 1.76.0-nightly (87e1447aa 2023-11-30)
binary: rustc
commit-hash: 87e1447aadaa2899ff6ccabe1fa669eb50fb60a1
commit-date: 2023-11-30
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.5

$ rustup toolchain uninstall 1.67

info: uninstalling toolchain '1.67-x86_64-unknown-linux-gnu'
info: toolchain '1.67-x86_64-unknown-linux-gnu' uninstalled

$ rustup toolchain list

stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
esp

公式: Directory overrides - Overrides - The rustup book 翻訳

$ rustup toolchain list

stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
esp

$ cd esp32-nostd-ssd1306
$ rustup override set esp

info: override toolchain for '/home/tomoyan/my_projects/esp32-nostd-ssd1306' set to 'esp'

$ rustup toolchain list  

stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
esp (override)

$ cd ..
$ rustup toolchain list

stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
esp

$ cd esp32-nostd-ssd1306
$ rustup toolchain list 

stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
esp (override)

オーバーライドの解除

$ rustup override unset

info: override toolchain for '/home/tomoyan/my_projects/esp32-nostd-ssd1306' removed

※ターゲットトリプル: {arch}-{vendor}-{sys}-{abi}
 {abi} を除く {arch}-{vendor}-{sys} のこと🤔
Fedora

$ rustup target list | grep installed

x86_64-unknown-linux-gnu (installed)

$ rustup target list

aarch64-apple-darwin
aarch64-apple-ios
aarch64-apple-ios-sim
aarch64-fuchsia
aarch64-linux-android
aarch64-pc-windows-msvc
aarch64-unknown-linux-gnu
aarch64-unknown-linux-musl
aarch64-unknown-none
aarch64-unknown-none-softfloat
arm-linux-androideabi
arm-unknown-linux-gnueabi
arm-unknown-linux-gnueabihf
arm-unknown-linux-musleabi
arm-unknown-linux-musleabihf
armebv7r-none-eabi
armebv7r-none-eabihf
armv5te-unknown-linux-gnueabi
armv5te-unknown-linux-musleabi
armv7-linux-androideabi
armv7-unknown-linux-gnueabi
armv7-unknown-linux-gnueabihf
armv7-unknown-linux-musleabi
armv7-unknown-linux-musleabihf
armv7a-none-eabi
armv7r-none-eabi
armv7r-none-eabihf
asmjs-unknown-emscripten
i586-pc-windows-msvc
i586-unknown-linux-gnu
i586-unknown-linux-musl
i686-linux-android
i686-pc-windows-gnu
i686-pc-windows-msvc
i686-unknown-freebsd
i686-unknown-linux-gnu
i686-unknown-linux-musl
mips-unknown-linux-gnu
mips-unknown-linux-musl
mips64-unknown-linux-gnuabi64
mips64-unknown-linux-muslabi64
mips64el-unknown-linux-gnuabi64
mips64el-unknown-linux-muslabi64
mipsel-unknown-linux-gnu
mipsel-unknown-linux-musl
nvptx64-nvidia-cuda
powerpc-unknown-linux-gnu
powerpc64-unknown-linux-gnu
powerpc64le-unknown-linux-gnu
riscv32i-unknown-none-elf
riscv32imac-unknown-none-elf
riscv32imc-unknown-none-elf
riscv64gc-unknown-linux-gnu
riscv64gc-unknown-none-elf
riscv64imac-unknown-none-elf
s390x-unknown-linux-gnu
sparc64-unknown-linux-gnu
sparcv9-sun-solaris
thumbv6m-none-eabi
thumbv7em-none-eabi
thumbv7em-none-eabihf
thumbv7m-none-eabi
thumbv7neon-linux-androideabi
thumbv7neon-unknown-linux-gnueabihf
thumbv8m.base-none-eabi
thumbv8m.main-none-eabi
thumbv8m.main-none-eabihf
wasm32-unknown-emscripten
wasm32-unknown-unknown
wasm32-wasi
x86_64-apple-darwin
x86_64-apple-ios
x86_64-fortanix-unknown-sgx
x86_64-fuchsia
x86_64-linux-android
x86_64-pc-solaris
x86_64-pc-windows-gnu
x86_64-pc-windows-msvc
x86_64-sun-solaris
x86_64-unknown-freebsd
x86_64-unknown-illumos
x86_64-unknown-linux-gnu (installed)
x86_64-unknown-linux-gnux32
x86_64-unknown-linux-musl
x86_64-unknown-netbsd
x86_64-unknown-none
x86_64-unknown-redox

DietPi

$ rustup target list | grep installed

arm-unknown-linux-gnueabihf (installed)

$ rustup target list

aarch64-apple-darwin
aarch64-apple-ios
aarch64-apple-ios-sim
aarch64-fuchsia
aarch64-linux-android
aarch64-pc-windows-msvc
aarch64-unknown-linux-gnu
aarch64-unknown-linux-musl
aarch64-unknown-none
aarch64-unknown-none-softfloat
arm-linux-androideabi
arm-unknown-linux-gnueabi
arm-unknown-linux-gnueabihf (installed)
arm-unknown-linux-musleabi
arm-unknown-linux-musleabihf
armebv7r-none-eabi
armebv7r-none-eabihf
armv5te-unknown-linux-gnueabi
armv5te-unknown-linux-musleabi
armv7-linux-androideabi
armv7-unknown-linux-gnueabi
armv7-unknown-linux-gnueabihf
armv7-unknown-linux-musleabi
armv7-unknown-linux-musleabihf
armv7a-none-eabi
armv7r-none-eabi
armv7r-none-eabihf
asmjs-unknown-emscripten
i586-pc-windows-msvc
i586-unknown-linux-gnu
i586-unknown-linux-musl
i686-linux-android
i686-pc-windows-gnu
i686-pc-windows-msvc
i686-unknown-freebsd
i686-unknown-linux-gnu
i686-unknown-linux-musl
mips-unknown-linux-gnu
mips-unknown-linux-musl
mips64-unknown-linux-gnuabi64
mips64-unknown-linux-muslabi64
mips64el-unknown-linux-gnuabi64
mips64el-unknown-linux-muslabi64
mipsel-unknown-linux-gnu
mipsel-unknown-linux-musl
nvptx64-nvidia-cuda
powerpc-unknown-linux-gnu
powerpc64-unknown-linux-gnu
powerpc64le-unknown-linux-gnu
riscv32i-unknown-none-elf
riscv32imac-unknown-none-elf
riscv32imc-unknown-none-elf
riscv64gc-unknown-linux-gnu
riscv64gc-unknown-none-elf
riscv64imac-unknown-none-elf
s390x-unknown-linux-gnu
sparc64-unknown-linux-gnu
sparcv9-sun-solaris
thumbv6m-none-eabi
thumbv7em-none-eabi
thumbv7em-none-eabihf
thumbv7m-none-eabi
thumbv7neon-linux-androideabi
thumbv7neon-unknown-linux-gnueabihf
thumbv8m.base-none-eabi
thumbv8m.main-none-eabi
thumbv8m.main-none-eabihf
wasm32-unknown-emscripten
wasm32-unknown-unknown
wasm32-wasi
x86_64-apple-darwin
x86_64-apple-ios
x86_64-fortanix-unknown-sgx
x86_64-fuchsia
x86_64-linux-android
x86_64-pc-solaris
x86_64-pc-windows-gnu
x86_64-pc-windows-msvc
x86_64-sun-solaris
x86_64-unknown-freebsd
x86_64-unknown-illumos
x86_64-unknown-linux-gnu
x86_64-unknown-linux-gnux32
x86_64-unknown-linux-musl
x86_64-unknown-netbsd
x86_64-unknown-redox

公式: Cross-compilation - The rustup book
クロスビルド可能なターゲットの一覧に存在するものは、ターゲットを追加するだけで済みます😊

$ rustup target add arm-unknown-linux-gnueabihf

info: downloading component 'rust-std' for 'arm-unknown-linux-gnueabihf'
info: installing component 'rust-std' for 'arm-unknown-linux-gnueabihf'
 22.5 MiB /  22.5 MiB (100 %)   8.1 MiB/s in  2s ETA:  0s

$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/tomoyan/.rustup

installed targets for active toolchain
--------------------------------------

arm-unknown-linux-gnueabihf
x86_64-unknown-linux-gnu

active toolchain
----------------

stable-x86_64-unknown-linux-gnu (default)
rustc 1.72.0 (5680fa18f 2023-08-23)

$ rustup target remove thumbv7em-none-eabihf

info: removing component 'rust-std' for 'thumbv7em-none-eabihf'

$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/tomoyan/.rustup

stable-x86_64-unknown-linux-gnu (default)
rustc 1.65.0 (897e37553 2022-11-02)

$ rustup self uninstall


Thanks for hacking in Rust!

This will uninstall all Rust toolchains and data, and remove
$HOME/.cargo/bin from your PATH environment variable.

Continue? (y/N) y -> y を入力して Enter

info: removing rustup home
info: removing cargo home
info: removing rustup binaries
info: rustup is uninstalled

ソースコード: mozilla/sccache: sccache is ccache with cloud storage

$ TMPDIR=/var/tmp cargo install sccache

    Updating crates.io index
  Downloaded sccache v0.3.0
  Downloaded 1 crate (272.5 KB) in 0.70s
  Installing sccache v0.3.0
  Downloaded async-trait v0.1.56
  Downloaded crypto-common v0.1.3
  Downloaded ar v0.9.0
  Downloaded digest v0.10.3
  Downloaded bincode v1.3.3
  Downloaded base64 v0.13.0
  Downloaded directories v4.0.1
  Downloaded zstd-safe v3.0.1+zstd.1.4.9
  Downloaded try-lock v0.2.3
  Downloaded hyper v0.14.19
  Downloaded unix_socket v0.5.0
  Downloaded xattr v0.2.3
  Downloaded daemonize v0.4.1
  Downloaded boxfnonce v0.1.1
  Downloaded md5 v0.3.8
  Downloaded language-tags v0.3.2
  Downloaded thiserror-impl v1.0.31
  Downloaded hyperx v1.4.0
  Downloaded openssl-sys v0.9.74
  Downloaded pulldown-cmark v0.0.3
  Downloaded mio v0.8.3
  Downloaded pin-project v1.0.10
  Downloaded openssl-macros v0.1.0
  Downloaded native-tls v0.2.10
  Downloaded bufstream v0.1.4
  Downloaded mime v0.3.16
  Downloaded openssl v0.10.40
  Downloaded getopts v0.2.21
  Downloaded blake3 v0.3.8
  Downloaded retry v1.3.1
  Downloaded redis v0.21.5
  Downloaded spin v0.5.2
  Downloaded tokio-native-tls v0.3.0
  Downloaded vte_generate_state_changes v0.1.1
  Downloaded tokio-serde v0.8.0
  Downloaded skeptic v0.4.0
  Downloaded constant_time_eq v0.1.5
  Downloaded futures-locks v0.7.0
  Downloaded dtoa v0.4.8
  Downloaded hmac v0.12.1
  Downloaded conhash v0.4.0
  Downloaded tokio-util v0.6.10
  Downloaded tower v0.4.12
  Downloaded untrusted v0.7.1
  Downloaded tower-layer v0.3.1
  Downloaded toml v0.5.9
  Downloaded tokio-util v0.7.3
  Downloaded memcached-rs v0.4.2
  Downloaded ipnet v2.5.0
  Downloaded httparse v1.7.1
  Downloaded http v0.2.8
  Downloaded aho-corasick v0.7.18
  Downloaded zstd-sys v1.4.20+zstd.1.4.9
  Downloaded tar v0.4.38
  Downloaded futures-macro v0.3.21
  Downloaded futures-sink v0.3.21
  Downloaded pin-utils v0.1.0
  Downloaded itoa v0.4.8
  Downloaded humantime v2.1.0
  Downloaded semver-parser v0.7.0
  Downloaded rand_chacha v0.2.2
  Downloaded rand_chacha v0.3.1
  Downloaded signal-hook-registry v1.4.0
  Downloaded rand_core v0.6.3
  Downloaded futures-task v0.3.21
  Downloaded foreign-types-shared v0.1.1
  Downloaded want v0.3.0
  Downloaded hyper-tls v0.5.0
  Downloaded slab v0.4.6
  Downloaded strip-ansi-escapes v0.1.1
  Downloaded sha-1 v0.10.0
  Downloaded semver v0.9.0
  Downloaded openssl-probe v0.1.5
  Downloaded tokio-macros v1.8.0
  Downloaded socket2 v0.4.4
  Downloaded flate2 v1.0.24
  Downloaded futures-channel v0.3.21
  Downloaded rand v0.8.5
  Downloaded futures-util v0.3.21
  Downloaded rand v0.7.3
  Downloaded zip v0.5.13
  Downloaded serde_urlencoded v0.7.1
  Downloaded pin-project-internal v1.0.10
  Downloaded rand v0.4.6
  Downloaded bytes v1.1.0
  Downloaded tower-service v0.3.1
  Downloaded thiserror v1.0.31
  Downloaded reqwest v0.11.11
  Downloaded termcolor v1.1.3
  Downloaded httpdate v1.0.2
  Downloaded crc32fast v1.3.2
  Downloaded block-buffer v0.10.2
  Downloaded linked-hash-map v0.5.4
  Downloaded sha2 v0.10.2
  Downloaded jobserver v0.1.24
  Downloaded arrayvec v0.5.2
  Downloaded foreign-types v0.3.2
  Downloaded byteorder v1.4.3
  Downloaded futures-io v0.3.21
  Downloaded futures v0.3.21
  Downloaded rand_core v0.5.1
  Downloaded cfg-if v0.1.10
  Downloaded ppv-lite86 v0.2.16
  Downloaded getrandom v0.1.16
  Downloaded http-body v0.4.5
  Downloaded futures-core v0.3.21
  Downloaded futures-executor v0.3.21
  Downloaded fnv v1.0.7
  Downloaded env_logger v0.9.0
  Downloaded md-5 v0.10.1
  Downloaded counted-array v0.1.2
  Downloaded combine v4.6.4
  Downloaded zstd v0.6.1+zstd.1.4.9
  Downloaded vte v0.10.1
  Downloaded local-encoding v0.2.0
  Downloaded crypto-mac v0.8.0
  Downloaded number_prefix v0.4.0
  Downloaded h2 v0.3.13
  Downloaded arrayref v0.3.6
  Downloaded tempdir v0.3.7
  Downloaded tokio v1.19.2
  Downloaded encoding_rs v0.8.31
  Downloaded ring v0.16.20
  Downloaded 123 crates (13.1 MB) in 3.04s (largest was `ring` at 5.1 MB)
  Downloaded parity-tokio-ipc v0.9.0
  Downloaded 1 crate (15.9 KB) in 0.36s
  Downloaded winapi v0.3.9
  Downloaded 1 crate (1.2 MB) in 0.37s
   Compiling libc v0.2.126
   Compiling cfg-if v1.0.0
   Compiling proc-macro2 v1.0.39
   Compiling unicode-ident v1.0.1
   Compiling syn v1.0.96
   Compiling autocfg v1.1.0
   Compiling log v0.4.17
   Compiling memchr v2.5.0
   Compiling once_cell v1.12.0
   Compiling version_check v0.9.4
   Compiling pin-project-lite v0.2.9
   Compiling futures-core v0.3.21
   Compiling bytes v1.1.0
   Compiling futures-sink v0.3.21
   Compiling typenum v1.15.0
   Compiling futures-channel v0.3.21
   Compiling futures-task v0.3.21
   Compiling pkg-config v0.3.25
   Compiling futures-util v0.3.21
   Compiling itoa v1.0.2
   Compiling pin-utils v0.1.0
   Compiling futures-io v0.3.21
   Compiling slab v0.4.6
   Compiling openssl v0.10.40
   Compiling serde v1.0.137
   Compiling bitflags v1.3.2
   Compiling fnv v1.0.7
   Compiling foreign-types-shared v0.1.1
   Compiling subtle v2.4.1
   Compiling getrandom v0.1.16
   Compiling percent-encoding v2.1.0
   Compiling matches v0.1.9
   Compiling ppv-lite86 v0.2.16
   Compiling native-tls v0.2.10
   Compiling tinyvec_macros v0.1.0
   Compiling unicode-width v0.1.9
   Compiling remove_dir_all v0.5.3
   Compiling httparse v1.7.1
   Compiling openssl-probe v0.1.5
   Compiling hashbrown v0.11.2
   Compiling tower-service v0.3.1
   Compiling unicode-bidi v0.3.8
   Compiling httpdate v1.0.2
   Compiling try-lock v0.2.3
   Compiling crc32fast v1.3.2
   Compiling arrayvec v0.5.2
   Compiling encoding_rs v0.8.31
   Compiling zstd-safe v3.0.1+zstd.1.4.9
   Compiling ryu v1.0.10
   Compiling serde_json v1.0.81
   Compiling cfg-if v0.1.10
   Compiling async-trait v0.1.56
   Compiling byteorder v1.4.3
   Compiling utf8parse v0.2.0
   Compiling adler v1.0.2
   Compiling semver-parser v0.7.0
   Compiling cpufeatures v0.2.2
   Compiling anyhow v1.0.57
   Compiling mime v0.3.16
   Compiling regex-syntax v0.6.26
   Compiling hyperx v1.4.0
   Compiling serde_derive v1.0.137
   Compiling md5 v0.3.8
   Compiling base64 v0.13.0
   Compiling ipnet v2.5.0
   Compiling termcolor v1.1.3
   Compiling same-file v1.0.6
   Compiling untrusted v0.7.1
   Compiling boxfnonce v0.1.1
   Compiling lazy_static v1.4.0
   Compiling constant_time_eq v0.1.5
   Compiling tower-layer v0.3.1
   Compiling fastrand v1.7.0
   Compiling itoa v0.4.8
   Compiling bufstream v0.1.4
   Compiling strsim v0.8.0
   Compiling ansi_term v0.12.1
   Compiling arrayref v0.3.6
   Compiling either v1.6.1
   Compiling dtoa v0.4.8
   Compiling humantime v2.1.0
   Compiling vec_map v0.8.2
   Compiling spin v0.5.2
   Compiling language-tags v0.3.2
   Compiling linked-hash-map v0.5.4
   Compiling counted-array v0.1.2
   Compiling number_prefix v0.4.0
   Compiling ar v0.9.0
   Compiling indexmap v1.8.2
   Compiling num-traits v0.2.15
   Compiling num-integer v0.1.45
   Compiling tracing-core v0.1.27
   Compiling generic-array v0.14.5
   Compiling unicase v2.6.0
   Compiling http v0.2.8
   Compiling foreign-types v0.3.2
   Compiling form_urlencoded v1.0.1
   Compiling tinyvec v1.6.0
   Compiling getopts v0.2.21
   Compiling textwrap v0.11.0
   Compiling miniz_oxide v0.5.3
   Compiling semver v0.9.0
   Compiling walkdir v2.3.2
   Compiling http-body v0.4.5
   Compiling unicode-normalization v0.1.19
   Compiling pulldown-cmark v0.0.3
   Compiling quote v1.0.18
   Compiling num_cpus v1.13.1
   Compiling signal-hook-registry v1.4.0
   Compiling socket2 v0.4.4
   Compiling getrandom v0.2.7
   Compiling atty v0.2.14
   Compiling time v0.1.44
   Compiling unix_socket v0.5.0
   Compiling dirs-sys v0.3.7
   Compiling xattr v0.2.3
   Compiling filetime v0.2.16
   Compiling tempfile v3.3.0
   Compiling jobserver v0.1.24
   Compiling daemonize v0.4.1
   Compiling which v4.2.5
   Compiling rand v0.4.6
   Compiling mio v0.8.3
   Compiling tracing v0.1.35
   Compiling want v0.3.0
   Compiling conhash v0.4.0
   Compiling aho-corasick v0.7.18
   Compiling idna v0.2.3
   Compiling serde_urlencoded v0.7.1
   Compiling bincode v1.3.3
   Compiling toml v0.5.9
   Compiling flate2 v1.0.24
   Compiling vte_generate_state_changes v0.1.1
   Compiling rand_core v0.6.3
   Compiling uuid v0.8.2
   Compiling rand_core v0.5.1
   Compiling clap v2.34.0
   Compiling directories v4.0.1
   Compiling tar v0.4.38
   Compiling cc v1.0.73
   Compiling tempdir v0.3.7
   Compiling tower v0.4.12
   Compiling regex v1.5.6
   Compiling crypto-common v0.1.3
   Compiling block-buffer v0.10.2
   Compiling digest v0.9.0
   Compiling crypto-mac v0.8.0
   Compiling url v2.2.2
   Compiling vte v0.10.1
   Compiling rand_chacha v0.3.1
   Compiling rand_chacha v0.2.2
   Compiling tokio-macros v1.8.0
   Compiling futures-macro v0.3.21
   Compiling openssl-macros v0.1.0
   Compiling thiserror-impl v1.0.31
   Compiling pin-project-internal v1.0.10
   Compiling openssl-sys v0.9.74
   Compiling zstd-sys v1.4.20+zstd.1.4.9
   Compiling blake3 v0.3.8
   Compiling ring v0.16.20
   Compiling skeptic v0.4.0
   Compiling chrono v0.4.19
   Compiling env_logger v0.9.0
   Compiling digest v0.10.3
   Compiling strip-ansi-escapes v0.1.1
   Compiling rand v0.8.5
   Compiling rand v0.7.3
   Compiling tokio v1.19.2
   Compiling thiserror v1.0.31
   Compiling pin-project v1.0.10
   Compiling local-encoding v0.2.0
   Compiling md-5 v0.10.1
   Compiling hmac v0.12.1
   Compiling sha-1 v0.10.0
   Compiling sha2 v0.10.2
   Compiling retry v1.3.1
   Compiling memcached-rs v0.4.2
   Compiling futures-executor v0.3.21
   Compiling tokio-util v0.7.3
   Compiling tokio-util v0.6.10
   Compiling futures-locks v0.7.0
   Compiling zip v0.5.13
   Compiling tokio-serde v0.8.0
   Compiling futures v0.3.21
   Compiling h2 v0.3.13
   Compiling combine v4.6.4
   Compiling hyper v0.14.19
   Compiling tokio-native-tls v0.3.0
   Compiling hyper-tls v0.5.0
   Compiling redis v0.21.5
   Compiling reqwest v0.11.11
   Compiling zstd v0.6.1+zstd.1.4.9
   Compiling sccache v0.3.0
    Finished release [optimized] target(s) in 5m 56s
  Installing /home/tomoyan/.cargo/bin/sccache
   Installed package `sccache v0.3.0` (executable `sccache`)

動作確認

$ sccache -h

sccache 0.3.0

USAGE:
    sccache [FLAGS] [OPTIONS] [cmd]...

FLAGS:
        --dist-auth       authenticate for distributed compilation
        --dist-status     show status of the distributed client
    -h, --help            Prints help information
    -s, --show-stats      show cache statistics
        --start-server    start background server
        --stop-server     stop background server
    -V, --version         Prints version information
    -z, --zero-stats      zero statistics counters

OPTIONS:
        --package-toolchain      package toolchain for distributed compilation
        --stats-format 
            set output format of statistics [default: text]  [possible values: text, json]


ARGS:
    ...

Enabled features:
    S3:        true
    Redis:     true
    Memcached: true
    GCS:       true
    Azure:     true

Rust の Cargo から sccache を利用するには RUSTC_WRAPPER 環境変数を設定する😉

$ echo 'export RUSTC_WRAPPER=$(which sccache)' >> .bashrc
$ . .bashrc
$ echo $RUSTC_WRAPPER

/home/tomoyan/.cargo/bin/sccache

または、

$ echo 'export RUSTC_WRAPPER=$(which sccache)' >> .profile
$ . .profile
$ echo $RUSTC_WRAPPER

/home/dietpi/.cargo/bin/sccache

sccache の統計情報を表示する🤔

$ sccache -s

Compile requests                      0
Compile requests executed             0
Cache hits                            0
Cache misses                          0
Cache timeouts                        0
Cache read errors                     0
Forced recaches                       0
Cache write errors                    0
Compilation failures                  0
Cache errors                          0
Non-cacheable compilations            0
Non-cacheable calls                   0
Non-compilation calls                 0
Unsupported compiler calls            0
Average cache write               0.000 s
Average cache read miss           0.000 s
Average cache read hit            0.000 s
Failed distributed compilations       0
Cache location                  Local disk: "/home/tomoyan/.cache/sccache"

インストール

$ cargo install coreutils

    Updating crates.io index
  Downloaded coreutils v0.0.25
  Downloaded 1 crate (1.5 MB) in 1.82s
  Installing coreutils v0.0.25
    Updating crates.io index
  Downloaded anstream v0.6.13
  Downloaded arrayref v0.3.7
  Downloaded anstyle v1.0.6
  Downloaded uu_df v0.0.25
  Downloaded bitflags v2.5.0
  Downloaded uu_echo v0.0.25
  Downloaded binary-heap-plus v0.5.0
  Downloaded uu_env v0.0.25
  Downloaded bigdecimal v0.4.3
  Downloaded console v0.15.8
  Downloaded anstyle-query v1.0.2
  Downloaded anstyle-parse v0.2.3
  Downloaded uu_expand v0.0.25
  Downloaded clap_complete v4.5.1
  Downloaded crossbeam-utils v0.8.19
  Downloaded uu_expr v0.0.25
  Downloaded uu_fmt v0.0.25
  Downloaded uu_false v0.0.25
  Downloaded uu_factor v0.0.25
  Downloaded chrono v0.4.35
  Downloaded uu_fold v0.0.25
  Downloaded cpufeatures v0.2.12
  Downloaded uu_pr v0.0.25
  Downloaded uu_join v0.0.25
  Downloaded uu_rm v0.0.25
  Downloaded uu_hashsum v0.0.25
  Downloaded uu_readlink v0.0.25
  Downloaded uu_od v0.0.25
  Downloaded uu_shuf v0.0.25
  Downloaded uu_head v0.0.25
  Downloaded uu_tail v0.0.25
  Downloaded uu_printenv v0.0.25
  Downloaded uu_seq v0.0.25
  Downloaded uu_ptx v0.0.25
  Downloaded uu_mv v0.0.25
  Downloaded uu_mktemp v0.0.25
  Downloaded uu_paste v0.0.25
  Downloaded uu_tac v0.0.25
  Downloaded uu_mkdir v0.0.25
  Downloaded uu_true v0.0.25
  Downloaded uu_nl v0.0.25
  Downloaded uu_printf v0.0.25
  Downloaded uu_rmdir v0.0.25
  Downloaded uu_ls v0.0.25
  Downloaded uu_test v0.0.25
  Downloaded uu_sum v0.0.25
  Downloaded uu_ln v0.0.25
  Downloaded uu_pwd v0.0.25
  Downloaded fastrand v2.0.2
  Downloaded uu_split v0.0.25
  Downloaded uu_tr v0.0.25
  Downloaded uu_tee v0.0.25
  Downloaded uu_link v0.0.25
  Downloaded uu_shred v0.0.25
  Downloaded uu_tsort v0.0.25
  Downloaded uu_sleep v0.0.25
  Downloaded uu_realpath v0.0.25
  Downloaded uu_touch v0.0.25
  Downloaded uu_yes v0.0.25
  Downloaded xattr v1.3.1
  Downloaded clap_mangen v0.2.20
  Downloaded uutils_term_grid v0.3.0
  Downloaded uu_unexpand v0.0.25
  Downloaded uu_truncate v0.0.25
  Downloaded uu_sort v0.0.25
  Downloaded uu_more v0.0.25
  Downloaded uu_numfmt v0.0.25
  Downloaded uu_dirname v0.0.25
  Downloaded uu_uniq v0.0.25
  Downloaded uucore v0.0.25
  Downloaded uu_wc v0.0.25
  Downloaded wild v2.2.1
  Downloaded uu_dircolors v0.0.25
  Downloaded uu_unlink v0.0.25
  Downloaded walkdir v2.5.0
  Downloaded uu_du v0.0.25
  Downloaded z85 v3.0.5
  Downloaded uu_vdir v0.0.25
  Downloaded uuhelp_parser v0.0.25
  Downloaded uucore_procs v0.0.25
  Downloaded const-random v0.1.18
  Downloaded cfg_aliases v0.1.1
  Downloaded data-encoding-macro-internal v0.1.12
  Downloaded data-encoding-macro v0.1.14
  Downloaded uu_base64 v0.0.25
  Downloaded uu_basename v0.0.25
  Downloaded match_cfg v0.1.0
  Downloaded uu_comm v0.0.25
  Downloaded uu_dir v0.0.25
  Downloaded uu_basenc v0.0.25
  Downloaded compare v0.1.0
  Downloaded constant_time_eq v0.3.0
  Downloaded clap_lex v0.7.0
  Downloaded hostname v0.3.1
  Downloaded uu_base32 v0.0.25
  Downloaded ctrlc v3.4.4
  Downloaded filetime v0.2.23
  Downloaded keccak v0.1.5
  Downloaded dlv-list v0.5.2
  Downloaded data-encoding v2.5.0
  Downloaded either v1.10.0
  Downloaded terminal_size v0.2.6
  Downloaded strsim v0.11.0
  Downloaded uu_date v0.0.25
  Downloaded self_cell v1.0.3
  Downloaded crossbeam-deque v0.8.5
  Downloaded uu_cut v0.0.25
  Downloaded phf_codegen v0.11.2
  Downloaded num-integer v0.1.46
  Downloaded phf_generator v0.11.2
  Downloaded uu_csplit v0.0.25
  Downloaded siphasher v0.3.11
  Downloaded lscolors v0.16.0
  Downloaded uu_cat v0.0.25
  Downloaded thiserror v1.0.58
  Downloaded pkg-config v0.3.30
  Downloaded phf_shared v0.11.2
  Downloaded md-5 v0.10.6
  Downloaded uu_cksum v0.0.25
  Downloaded phf v0.11.2
  Downloaded thiserror-impl v1.0.58
  Downloaded ordered-multimap v0.6.0
  Downloaded quick-error v2.0.1
  Downloaded os_display v0.1.3
  Downloaded getrandom v0.2.12
  Downloaded fs_extra v1.3.0
  Downloaded bytecount v0.6.7
  Downloaded blake2b_simd v1.0.2
  Downloaded iana-time-zone v0.1.60
  Downloaded rust-ini v0.19.0
  Downloaded roff v0.2.1
  Downloaded onig v6.4.0
  Downloaded uu_dd v0.0.25
  Downloaded nu-ansi-term v0.49.0
  Downloaded memmap2 v0.9.4
  Downloaded sm3 v0.4.2
  Downloaded uu_cp v0.0.25
  Downloaded clap v4.5.3
  Downloaded tempfile v3.10.1
  Downloaded num-traits v0.2.18
  Downloaded log v0.4.21
  Downloaded half v2.4.0
  Downloaded crossbeam-epoch v0.9.18
  Downloaded parse_datetime v0.5.0
  Downloaded notify v6.0.1
  Downloaded fundu-core v0.3.0
  Downloaded textwrap v0.16.1
  Downloaded rayon-core v1.12.1
  Downloaded indicatif v0.17.8
  Downloaded cc v1.0.90
  Downloaded fundu v2.0.0
  Downloaded crossbeam-channel v0.5.12
  Downloaded num-bigint v0.4.4
  Downloaded unicode-segmentation v1.11.0
  Downloaded mio v0.8.11
  Downloaded hashbrown v0.13.2
  Downloaded itertools v0.12.1
  Downloaded clap_builder v4.5.2
  Downloaded linux-raw-sys v0.4.13
  Downloaded rayon v1.10.0
  Downloaded blake3 v1.5.1
  Downloaded nix v0.28.0
  Downloaded rustix v0.37.27
  Downloaded rustix v0.38.32
  Downloaded onig_sys v69.8.1
  Downloaded sha3 v0.10.8
  Downloaded 166 crates (8.3 MB) in 5.35s (largest was `linux-raw-sys` at 1.5 MB)
   Compiling libc v0.2.153
   Compiling cfg-if v1.0.0
   Compiling bitflags v2.5.0
   Compiling version_check v0.9.4
   Compiling typenum v1.17.0
   Compiling proc-macro2 v1.0.79
   Compiling generic-array v0.14.7
   Compiling rustix v0.38.32
   Compiling unicode-ident v1.0.12
   Compiling linux-raw-sys v0.4.13
   Compiling quote v1.0.35
   Compiling cc v1.0.90
   Compiling utf8parse v0.2.1
   Compiling memchr v2.7.1
   Compiling block-buffer v0.10.4
   Compiling crypto-common v0.1.6
   Compiling digest v0.10.7
   Compiling anstyle-parse v0.2.3
   Compiling anstyle v1.0.6
   Compiling colorchoice v1.0.0
   Compiling anstyle-query v1.0.2
   Compiling unicode-width v0.1.11
   Compiling anstream v0.6.13
   Compiling clap_lex v0.7.0
   Compiling cfg_aliases v0.1.1
   Compiling syn v1.0.109
   Compiling strsim v0.11.0
   Compiling nix v0.28.0
   Compiling terminal_size v0.3.0
   Compiling clap_builder v4.5.2
   Compiling blake3 v1.5.1
   Compiling syn v2.0.55
   Compiling constant_time_eq v0.3.0
   Compiling arrayref v0.3.7
   Compiling same-file v1.0.6
   Compiling thiserror v1.0.58
   Compiling cpufeatures v0.2.12
   Compiling either v1.10.0
   Compiling data-encoding v2.5.0
   Compiling arrayvec v0.7.4
   Compiling walkdir v2.5.0
   Compiling data-encoding-macro-internal v0.1.12
   Compiling clap v4.5.3
   Compiling uuhelp_parser v0.0.25
   Compiling thiserror-impl v1.0.58
   Compiling keccak v0.1.5
   Compiling once_cell v1.19.0
   Compiling sha3 v0.10.8
   Compiling data-encoding-macro v0.1.14
   Compiling uucore_procs v0.0.25
   Compiling blake2b_simd v1.0.2
   Compiling itertools v0.12.1
   Compiling sha1 v0.10.6
   Compiling sha2 v0.10.8
   Compiling xattr v1.3.1
   Compiling os_display v0.1.3
   Compiling md-5 v0.10.6
   Compiling sm3 v0.4.2
   Compiling z85 v3.0.5
   Compiling dunce v1.0.4
   Compiling hex v0.4.3
   Compiling glob v0.3.1
   Compiling wild v2.2.1
   Compiling autocfg v1.1.0
   Compiling uucore v0.0.25
   Compiling aho-corasick v1.1.3
   Compiling num-traits v0.2.18
   Compiling regex-syntax v0.8.2
   Compiling crossbeam-utils v0.8.19
   Compiling crunchy v0.2.2
   Compiling iana-time-zone v0.1.60
   Compiling chrono v0.4.35
   Compiling regex-automata v0.4.6
   Compiling getrandom v0.2.12
   Compiling bitflags v1.3.2
   Compiling tiny-keccak v2.0.2
   Compiling rand_core v0.6.4
   Compiling ppv-lite86 v0.2.17
   Compiling rand_chacha v0.3.1
   Compiling log v0.4.21
   Compiling signal-hook v0.3.17
   Compiling number_prefix v0.4.0
   Compiling const-random-macro v0.1.16
   Compiling rand v0.8.5
   Compiling mio v0.8.11
   Compiling lock_api v0.4.11
   Compiling num-bigint v0.4.4
   Compiling signal-hook-registry v1.4.1
   Compiling siphasher v0.3.11
   Compiling parking_lot_core v0.9.9
   Compiling pkg-config v0.3.30
   Compiling portable-atomic v1.6.0
   Compiling regex v1.10.4
   Compiling io-lifetimes v1.0.11
   Compiling smallvec v1.13.2
   Compiling onig_sys v69.8.1
   Compiling phf_shared v0.11.2
   Compiling const-random v0.1.18
   Compiling crossbeam-epoch v0.9.18
   Compiling num-integer v0.1.46
   Compiling filetime v0.2.23
   Compiling rayon-core v1.12.1
   Compiling libm v0.2.8
   Compiling rustix v0.37.27
   Compiling match_cfg v0.1.0
   Compiling scopeguard v1.2.0
   Compiling nu-ansi-term v0.49.0
   Compiling lazy_static v1.4.0
   Compiling console v0.15.8
   Compiling lscolors v0.16.0
   Compiling hostname v0.3.1
   Compiling crossbeam-deque v0.8.5
   Compiling dlv-list v0.5.2
   Compiling phf_generator v0.11.2
   Compiling bigdecimal v0.4.3
   Compiling uutils_term_grid v0.3.0
   Compiling inotify-sys v0.1.5
   Compiling fundu-core v0.3.0
   Compiling fastrand v2.0.2
   Compiling linux-raw-sys v0.3.8
   Compiling hashbrown v0.13.2
   Compiling ordered-multimap v0.6.0
   Compiling fundu v2.0.0
   Compiling tempfile v3.10.1
   Compiling inotify v0.9.6
   Compiling uu_ls v0.0.25
   Compiling indicatif v0.17.8
   Compiling uu_factor v0.0.25
   Compiling parking_lot v0.12.1
   Compiling phf_codegen v0.11.2
   Compiling signal-hook-mio v0.2.3
   Compiling parse_datetime v0.5.0
   Compiling crossbeam-channel v0.5.12
   Compiling uu_base32 v0.0.25
   Compiling quick-error v2.0.1
   Compiling compare v0.1.0
   Compiling minimal-lexical v0.2.1
   Compiling binary-heap-plus v0.5.0
   Compiling notify v6.0.1
   Compiling crossterm v0.27.0
   Compiling nom v7.1.3
   Compiling rayon v1.10.0
   Compiling coreutils v0.0.25
   Compiling terminal_size v0.2.6
   Compiling rust-ini v0.19.0
   Compiling onig v6.4.0
   Compiling bstr v1.9.1
   Compiling ctrlc v3.4.4
   Compiling memmap2 v0.9.4
   Compiling half v2.4.0
   Compiling roff v0.2.1
   Compiling smawk v0.3.2
   Compiling fs_extra v1.3.0
   Compiling unicode-linebreak v0.1.5
   Compiling fnv v1.0.7
   Compiling self_cell v1.0.3
   Compiling gcd v2.3.0
   Compiling unicode-segmentation v1.11.0
   Compiling bytecount v0.6.7
   Compiling byteorder v1.5.0
   Compiling uu_dd v0.0.25
   Compiling uu_wc v0.0.25
   Compiling uu_od v0.0.25
   Compiling uu_more v0.0.25
   Compiling uu_sort v0.0.25
   Compiling uu_mv v0.0.25
   Compiling textwrap v0.16.1
   Compiling uu_cut v0.0.25
   Compiling clap_mangen v0.2.20
   Compiling uu_tac v0.0.25
   Compiling uu_expr v0.0.25
   Compiling uu_env v0.0.25
   Compiling uu_seq v0.0.25
   Compiling uu_tr v0.0.25
   Compiling uu_tail v0.0.25
   Compiling phf v0.11.2
   Compiling uu_cp v0.0.25
   Compiling uu_pr v0.0.25
   Compiling uu_basenc v0.0.25
   Compiling uu_base64 v0.0.25
   Compiling uu_touch v0.0.25
   Compiling uu_date v0.0.25
   Compiling uu_dir v0.0.25
   Compiling uu_vdir v0.0.25
   Compiling uu_mktemp v0.0.25
   Compiling uu_sleep v0.0.25
   Compiling uu_ptx v0.0.25
   Compiling uu_csplit v0.0.25
   Compiling uu_hashsum v0.0.25
   Compiling uu_nl v0.0.25
   Compiling uu_shuf v0.0.25
   Compiling uu_shred v0.0.25
   Compiling uu_du v0.0.25
   Compiling uu_readlink v0.0.25
   Compiling uu_link v0.0.25
   Compiling uu_split v0.0.25
   Compiling uu_rmdir v0.0.25
   Compiling uu_printf v0.0.25
   Compiling uu_rm v0.0.25
   Compiling uu_yes v0.0.25
   Compiling uu_uniq v0.0.25
   Compiling uu_dirname v0.0.25
   Compiling uu_realpath v0.0.25
   Compiling uu_df v0.0.25
   Compiling uu_join v0.0.25
   Compiling uu_dircolors v0.0.25
   Compiling uu_sum v0.0.25
   Compiling uu_paste v0.0.25
   Compiling uu_tsort v0.0.25
   Compiling uu_numfmt v0.0.25
   Compiling uu_true v0.0.25
   Compiling uu_expand v0.0.25
   Compiling uu_unexpand v0.0.25
   Compiling uu_mkdir v0.0.25
   Compiling uu_false v0.0.25
   Compiling uu_cat v0.0.25
   Compiling uu_pwd v0.0.25
   Compiling uu_unlink v0.0.25
   Compiling uu_basename v0.0.25
   Compiling uu_printenv v0.0.25
   Compiling uu_tee v0.0.25
   Compiling uu_cksum v0.0.25
   Compiling uu_test v0.0.25
   Compiling uu_fold v0.0.25
   Compiling uu_ln v0.0.25
   Compiling uu_head v0.0.25
   Compiling uu_comm v0.0.25
   Compiling uu_echo v0.0.25
   Compiling uu_fmt v0.0.25
   Compiling uu_truncate v0.0.25
   Compiling clap_complete v4.5.1
    Finished release [optimized] target(s) in 5m 36s
  Installing /home/tomoyan/.cargo/bin/coreutils
   Installed package `coreutils v0.0.25` (executable `coreutils`)

使い方

$ coreutils du --help

Estimate file space usage

Usage: coreutils du [OPTION]... [FILE]...
       coreutils du [OPTION]... --files0-from=F

Options:
      --help                 Print help information.
  -a, --all                  write counts for all files, not just directories
      --apparent-size        print apparent sizes, rather than disk usage although the apparent size is
                             usually smaller, it may be larger due to holes in ('sparse') files, internal
                             fragmentation, indirect blocks, and the like
  -B, --block-size <SIZE>    scale sizes by SIZE before printing them. E.g., '-BM' prints sizes in units of
                             1,048,576 bytes. See SIZE format below.
  -b, --bytes                equivalent to '--apparent-size --block-size=1'
  -c, --total                produce a grand total
  -d, --max-depth <N>        print the total for a directory (or file, with --all) only if it is N or fewer
                             levels below the command line argument;  --max-depth=0 is the same as --summarize
  -h, --human-readable       print sizes in human readable format (e.g., 1K 234M 2G)
      --inodes               list inode usage information instead of block usage like --block-size=1K
  -k                         like --block-size=1K
  -l, --count-links          count sizes many times if hard linked
  -L, --dereference          follow all symbolic links
  -D, --dereference-args     follow only symlinks that are listed on the command line [short aliases: H]
  -P, --no-dereference       don't follow any symbolic links (this is the default)
  -m                         like --block-size=1M
  -0, --null                 end each output line with 0 byte rather than newline
  -S, --separate-dirs        do not include size of subdirectories
  -s, --summarize            display only a total for each argument
      --si                   like -h, but use powers of 1000 not 1024
  -x, --one-file-system      skip directories on different file systems
  -t, --threshold <SIZE>     exclude entries smaller than SIZE if positive, or entries greater than SIZE if
                             negative
  -v, --verbose              verbose mode (option not present in GNU/Coreutils)
      --exclude <PATTERN>    exclude files that match PATTERN
  -X, --exclude-from <FILE>  exclude files that match any pattern in FILE
      --files0-from <FILE>   summarize device usage of the NUL-terminated file names specified in file F; if F
                             is -, then read names from standard input
      --time[=<WORD>...]     show time of the last modification of any file in the directory, or any of its
                             subdirectories. If WORD is given, show time as WORD instead of modification time:
                             atime, access, use, ctime, status, birth or creation [possible values: atime,
                             access, use, ctime, status, birth, creation]
      --time-style <STYLE>   show times using style STYLE: full-iso, long-iso, iso, +FORMAT FORMAT is
                             interpreted like 'date'
  -V, --version              Print version

Display values are in units of the first available SIZE from --block-size,
and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

SIZE is an integer and optional unit (example: 10M is 10*1024*1024).
Units are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB,... (powers
of 1000).

PATTERN allows some advanced exclusions. For example, the following syntaxes
are supported:
? will match only one character
* will match zero or more characters
{a,b} will match a or b

$ cargo install sccache

    Updating crates.io index
  Downloaded sccache v0.3.0
  Downloaded 1 crate (272.5 KB) in 1.17s
  Installing sccache v0.3.0
  Downloaded bitflags v1.3.2
  ...
   Compiling rand v0.8.5
   Compiling rand v0.7.3
error: failed to run custom build command for `openssl-sys v0.9.75`

Caused by:
  process didn't exit successfully: `/tmp/cargo-installCiIUHG/release/build/openssl-sys-7bf1e8bf5be1b2d6/build-script-main` (exit status: 101)
  --- stdout
  cargo:rustc-cfg=const_fn
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR
  X86_64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
  OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR
  X86_64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
  OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_GNU_OPENSSL_DIR
  X86_64_UNKNOWN_LINUX_GNU_OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_DIR
  OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=OPENSSL_STATIC
  cargo:rerun-if-env-changed=OPENSSL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  run pkg_config fail: "`\"pkg-config\" \"--libs\" \"--cflags\" \"openssl\"` did not exit successfully: exit status: 1\nerror: could not find system library 'openssl' required by the 'openssl-sys' crate\n\n--- stderr\nPackage openssl was not found in the pkg-config search path.\nPerhaps you should add the directory containing `openssl.pc'\nto the PKG_CONFIG_PATH environment variable\nPackage 'openssl', required by 'virtual:world', not found\n"

  --- stderr
  thread 'main' panicked at '

  Could not find directory of OpenSSL installation, and this `-sys` crate cannot
  proceed without this knowledge. If OpenSSL is installed and this crate had
  trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
  compilation process.

  Make sure you also have the development packages of openssl installed.
  For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.

  If you're in a situation where you think the directory *should* be found
  automatically, please open a bug at https://github.com/sfackler/rust-openssl
  and include information about your system as well as this message.

  $HOST = x86_64-unknown-linux-gnu
  $TARGET = x86_64-unknown-linux-gnu
  openssl-sys = 0.9.75

  ', /home/tomoyan/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.75/build/find_normal.rs:191:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: failed to compile `sccache v0.3.0`, intermediate artifacts can be found at `/tmp/cargo-installCiIUHG`

Ubuntu では libssl-dev を、Fedora では openssl-devel をインストールしてから再実行する🤔

$ sudo dnf install openssl-devel

Fedora 36 - x86_64 - Updates                                                  5.8 kB/s | 5.5 kB     00:00    
Fedora 36 - x86_64 - Updates                                                  273 kB/s | 515 kB     00:01    
Fedora Modular 36 - x86_64 - Updates                                          6.7 kB/s | 4.8 kB     00:00    
依存関係が解決しました。
==============================================================================================================
 パッケージ                  アーキテクチャー     バージョン                      リポジトリー          サイズ
==============================================================================================================
インストール:
 openssl-devel               x86_64               1:3.0.5-1.fc36                  updates               3.0 M

トランザクションの概要
==============================================================================================================
インストール  1 パッケージ

ダウンロードサイズの合計: 3.0 M
インストール後のサイズ: 4.6 M
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
openssl-devel-3.0.5-1.fc36.x86_64.rpm                                         2.3 MB/s | 3.0 MB     00:01    
--------------------------------------------------------------------------------------------------------------
合計                                                                          1.5 MB/s | 3.0 MB     00:02     
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                                                      1/1 
  インストール中   : openssl-devel-1:3.0.5-1.fc36.x86_64                                                  1/1 
  scriptletの実行中: openssl-devel-1:3.0.5-1.fc36.x86_64                                                  1/1 
  検証             : openssl-devel-1:3.0.5-1.fc36.x86_64                                                  1/1 

インストール済み:
  openssl-devel-1:3.0.5-1.fc36.x86_64                                                                         

完了しました!

$ cargo install sccache

    Updating crates.io index
  Downloaded sccache v0.3.0
  Downloaded 1 crate (272.5 KB) in 2.44s
  Installing sccache v0.3.0
  Downloaded async-trait v0.1.56
  ...
   Compiling local-encoding v0.2.0
   Compiling tokio v1.19.2
error: failed to write /tmp/cargo-installcx83Fu/release/deps/rmetaqzpZIF/lib.rmeta: No space left on device (os error 28)
error: could not compile `tokio` due to previous error
warning: build failed, waiting for other jobs to finish...
error: failed to compile `sccache v0.3.0`, intermediate artifacts can be found at `/tmp/cargo-installcx83Fu`

/tmp が溢れている😱

$ df -BM

Filesystem     1M-blocks   Used Available Use% Mounted on
/dev/root        118989M 13156M   101048M  12% /
devtmpfs            183M     0M      183M   0% /dev
tmpfs               215M     0M      215M   0% /dev/shm
tmpfs                86M     9M       78M  10% /run
tmpfs                 5M     1M        5M   1% /run/lock
tmpfs               428M   426M        3M 100% /tmp
tmpfs                50M     1M       50M   1% /var/log
/dev/mmcblk0p1      127M    51M       76M  41% /boot
tmpfs                43M     1M       43M   1% /run/user/0
tmpfs                43M     1M       43M   1% /run/user/106
tmpfs                43M     1M       43M   1% /run/user/1000

tmp を掃除する😊

$ rm -rf /tmp/cargo-*
$ rm -rf /var/tmp/cargo-*

一時作業ディレクトリを /var/tmp にしてビルドを再実行する😊

$ TMPDIR=/var/tmp cargo install sccache

   Updating crates.io index
 Installing sccache v0.3.0
   Compiling libc v0.2.126
  ...

$ rustup self uninstall



Thanks for hacking in Rust!

This will uninstall all Rust toolchains and data, and remove
$HOME/.cargo/bin from your PATH environment variable.

Continue? (y/N) y -> y を入力して Enter

info: removing rustup home
info: removing cargo home
info: removing rustup binaries
info: rustup is uninstalled

インストーラスクリプトの内容

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | cat
#!/bin/sh
# shellcheck shell=dash
 
# This is just a little script that can be downloaded from the internet to
# install rustup. It just does platform detection, downloads the installer
# and runs it.
 
# It runs on Unix shells like {a,ba,da,k,z}sh. It uses the common `local`
# extension. Note: Most shells limit `local` to 1 var per line, contra bash.
 
if [ "$KSH_VERSION" = 'Version JM 93t+ 2010-03-05' ]; then
    # The version of ksh93 that ships with many illumos systems does not
    # support the "local" extension.  Print a message rather than fail in
    # subtle ways later on:
    echo 'rustup does not work with this ksh93 version; please try bash!' >&2
    exit 1
fi
 
 
set -u
 
# If RUSTUP_UPDATE_ROOT is unset or empty, default it.
RUSTUP_UPDATE_ROOT="${RUSTUP_UPDATE_ROOT:-https://static.rust-lang.org/rustup}"
 
#XXX: If you change anything here, please make the same changes in setup_mode.rs
usage() {
    cat 1>&2 <<EOF
rustup-init 1.24.3 (c1c769109 2021-05-31)
The installer for rustup
 
USAGE:
    rustup-init [FLAGS] [OPTIONS]
 
FLAGS:
    -v, --verbose           Enable verbose output
    -q, --quiet             Disable progress output
    -y                      Disable confirmation prompt.
        --no-modify-path    Don't configure the PATH environment variable
    -h, --help              Prints help information
    -V, --version           Prints version information
 
OPTIONS:
        --default-host <default-host>              Choose a default host triple
        --default-toolchain <default-toolchain>    Choose a default toolchain to install
        --default-toolchain none                   Do not install any toolchains
        --profile [minimal|default|complete]       Choose a profile
    -c, --component <components>...                Component name to also install
    -t, --target <targets>...                      Target name to also install
EOF
}
 
main() {
    downloader --check
    need_cmd uname
    need_cmd mktemp
    need_cmd chmod
    need_cmd mkdir
    need_cmd rm
    need_cmd rmdir
 
    get_architecture || return 1
    local _arch="$RETVAL"
    assert_nz "$_arch" "arch"
 
    local _ext=""
    case "$_arch" in
        *windows*)
            _ext=".exe"
            ;;
    esac
 
    local _url="${RUSTUP_UPDATE_ROOT}/dist/${_arch}/rustup-init${_ext}"
 
    local _dir
    _dir="$(ensure mktemp -d)"
    local _file="${_dir}/rustup-init${_ext}"
 
    local _ansi_escapes_are_valid=false
    if [ -t 2 ]; then
        if [ "${TERM+set}" = 'set' ]; then
            case "$TERM" in
                xterm*|rxvt*|urxvt*|linux*|vt*)
                    _ansi_escapes_are_valid=true
                ;;
            esac
        fi
    fi
 
    # check if we have to use /dev/tty to prompt the user
    local need_tty=yes
    for arg in "$@"; do
        case "$arg" in
            -h|--help)
                usage
                exit 0
                ;;
            -y)
                # user wants to skip the prompt -- we don't need /dev/tty
                need_tty=no
                ;;
            *)
                ;;
        esac
    done
 
    if $_ansi_escapes_are_valid; then
        printf "\33[1minfo:\33[0m downloading installer\n" 1>&2
    else
        printf '%s\n' 'info: downloading installer' 1>&2
    fi
 
    ensure mkdir -p "$_dir"
    ensure downloader "$_url" "$_file" "$_arch"
    ensure chmod u+x "$_file"
    if [ ! -x "$_file" ]; then
        printf '%s\n' "Cannot execute $_file (likely because of mounting /tmp as noexec)." 1>&2
        printf '%s\n' "Please copy the file to a location where you can execute binaries and run ./rustup-init${_ext}." 1>&2
        exit 1
    fi
 
    if [ "$need_tty" = "yes" ]; then
        # The installer is going to want to ask for confirmation by
        # reading stdin.  This script was piped into `sh` though and
        # doesn't have stdin to pass to its children. Instead we're going
        # to explicitly connect /dev/tty to the installer's stdin.
        if [ ! -t 1 ]; then
            err "Unable to run interactively. Run with -y to accept defaults, --help for additional options"
        fi
 
        ignore "$_file" "$@" < /dev/tty
    else
        ignore "$_file" "$@"
    fi
 
    local _retval=$?
 
    ignore rm "$_file"
    ignore rmdir "$_dir"
 
    return "$_retval"
}
 
check_proc() {
    # Check for /proc by looking for the /proc/self/exe link
    # This is only run on Linux
    if ! test -L /proc/self/exe ; then
        err "fatal: Unable to find /proc/self/exe.  Is /proc mounted?  Installation cannot proceed without /proc."
    fi
}
 
get_bitness() {
    need_cmd head
    # Architecture detection without dependencies beyond coreutils.
    # ELF files start out "\x7fELF", and the following byte is
    #   0x01 for 32-bit and
    #   0x02 for 64-bit.
    # The printf builtin on some shells like dash only supports octal
    # escape sequences, so we use those.
    local _current_exe_head
    _current_exe_head=$(head -c 5 /proc/self/exe )
    if [ "$_current_exe_head" = "$(printf '\177ELF\001')" ]; then
        echo 32
    elif [ "$_current_exe_head" = "$(printf '\177ELF\002')" ]; then
        echo 64
    else
        err "unknown platform bitness"
    fi
}
 
is_host_amd64_elf() {
    need_cmd head
    need_cmd tail
    # ELF e_machine detection without dependencies beyond coreutils.
    # Two-byte field at offset 0x12 indicates the CPU,
    # but we're interested in it being 0x3E to indicate amd64, or not that.
    local _current_exe_machine
    _current_exe_machine=$(head -c 19 /proc/self/exe | tail -c 1)
    [ "$_current_exe_machine" = "$(printf '\076')" ]
}
 
get_endianness() {
    local cputype=$1
    local suffix_eb=$2
    local suffix_el=$3
 
    # detect endianness without od/hexdump, like get_bitness() does.
    need_cmd head
    need_cmd tail
 
    local _current_exe_endianness
    _current_exe_endianness="$(head -c 6 /proc/self/exe | tail -c 1)"
    if [ "$_current_exe_endianness" = "$(printf '\001')" ]; then
        echo "${cputype}${suffix_el}"
    elif [ "$_current_exe_endianness" = "$(printf '\002')" ]; then
        echo "${cputype}${suffix_eb}"
    else
        err "unknown platform endianness"
    fi
}
 
get_architecture() {
    local _ostype _cputype _bitness _arch _clibtype
    _ostype="$(uname -s)"
    _cputype="$(uname -m)"
    _clibtype="gnu"
 
    if [ "$_ostype" = Linux ]; then
        if [ "$(uname -o)" = Android ]; then
            _ostype=Android
        fi
        if ldd --version 2>&1 | grep -q 'musl'; then
            _clibtype="musl"
        fi
    fi
 
    if [ "$_ostype" = Darwin ] && [ "$_cputype" = i386 ]; then
        # Darwin `uname -m` lies
        if sysctl hw.optional.x86_64 | grep -q ': 1'; then
            _cputype=x86_64
        fi
    fi
 
    if [ "$_ostype" = SunOS ]; then
        # Both Solaris and illumos presently announce as "SunOS" in "uname -s"
        # so use "uname -o" to disambiguate.  We use the full path to the
        # system uname in case the user has coreutils uname first in PATH,
        # which has historically sometimes printed the wrong value here.
        if [ "$(/usr/bin/uname -o)" = illumos ]; then
            _ostype=illumos
        fi
 
        # illumos systems have multi-arch userlands, and "uname -m" reports the
        # machine hardware name; e.g., "i86pc" on both 32- and 64-bit x86
        # systems.  Check for the native (widest) instruction set on the
        # running kernel:
        if [ "$_cputype" = i86pc ]; then
            _cputype="$(isainfo -n)"
        fi
    fi
 
    case "$_ostype" in
 
        Android)
            _ostype=linux-android
            ;;
 
        Linux)
            check_proc
            _ostype=unknown-linux-$_clibtype
            _bitness=$(get_bitness)
            ;;
 
        FreeBSD)
            _ostype=unknown-freebsd
            ;;
 
        NetBSD)
            _ostype=unknown-netbsd
            ;;
 
        DragonFly)
            _ostype=unknown-dragonfly
            ;;
 
        Darwin)
            _ostype=apple-darwin
            ;;
 
        illumos)
            _ostype=unknown-illumos
            ;;
 
        MINGW* | MSYS* | CYGWIN*)
            _ostype=pc-windows-gnu
            ;;
 
        *)
            err "unrecognized OS type: $_ostype"
            ;;
 
    esac
 
    case "$_cputype" in
 
        i386 | i486 | i686 | i786 | x86)
            _cputype=i686
            ;;
 
        xscale | arm)
            _cputype=arm
            if [ "$_ostype" = "linux-android" ]; then
                _ostype=linux-androideabi
            fi
            ;;
 
        armv6l)
            _cputype=arm
            if [ "$_ostype" = "linux-android" ]; then
                _ostype=linux-androideabi
            else
                _ostype="${_ostype}eabihf"
            fi
            ;;
 
        armv7l | armv8l)
            _cputype=armv7
            if [ "$_ostype" = "linux-android" ]; then
                _ostype=linux-androideabi
            else
                _ostype="${_ostype}eabihf"
            fi
            ;;
 
        aarch64 | arm64)
            _cputype=aarch64
            ;;
 
        x86_64 | x86-64 | x64 | amd64)
            _cputype=x86_64
            ;;
 
        mips)
            _cputype=$(get_endianness mips '' el)
            ;;
 
        mips64)
            if [ "$_bitness" -eq 64 ]; then
                # only n64 ABI is supported for now
                _ostype="${_ostype}abi64"
                _cputype=$(get_endianness mips64 '' el)
            fi
            ;;
 
        ppc)
            _cputype=powerpc
            ;;
 
        ppc64)
            _cputype=powerpc64
            ;;
 
        ppc64le)
            _cputype=powerpc64le
            ;;
 
        s390x)
            _cputype=s390x
            ;;
        riscv64)
            _cputype=riscv64gc
            ;;
        *)
            err "unknown CPU type: $_cputype"
 
    esac
 
    # Detect 64-bit linux with 32-bit userland
    if [ "${_ostype}" = unknown-linux-gnu ] && [ "${_bitness}" -eq 32 ]; then
        case $_cputype in
            x86_64)
                if [ -n "${RUSTUP_CPUTYPE:-}" ]; then
                    _cputype="$RUSTUP_CPUTYPE"
                else {
                    # 32-bit executable for amd64 = x32
                    if is_host_amd64_elf; then {
                         echo "This host is running an x32 userland; as it stands, x32 support is poor," 1>&2
                         echo "and there isn't a native toolchain -- you will have to install" 1>&2
                         echo "multiarch compatibility with i686 and/or amd64, then select one" 1>&2
                         echo "by re-running this script with the RUSTUP_CPUTYPE environment variable" 1>&2
                         echo "set to i686 or x86_64, respectively." 1>&2
                         echo 1>&2
                         echo "You will be able to add an x32 target after installation by running" 1>&2
                         echo "  rustup target add x86_64-unknown-linux-gnux32" 1>&2
                         exit 1
                    }; else
                        _cputype=i686
                    fi
                }; fi
                ;;
            mips64)
                _cputype=$(get_endianness mips '' el)
                ;;
            powerpc64)
                _cputype=powerpc
                ;;
            aarch64)
                _cputype=armv7
                if [ "$_ostype" = "linux-android" ]; then
                    _ostype=linux-androideabi
                else
                    _ostype="${_ostype}eabihf"
                fi
                ;;
            riscv64gc)
                err "riscv64 with 32-bit userland unsupported"
                ;;
        esac
    fi
 
    # Detect armv7 but without the CPU features Rust needs in that build,
    # and fall back to arm.
    # See https://github.com/rust-lang/rustup.rs/issues/587.
    if [ "$_ostype" = "unknown-linux-gnueabihf" ] && [ "$_cputype" = armv7 ]; then
        if ensure grep '^Features' /proc/cpuinfo | grep -q -v neon; then
            # At least one processor does not have NEON.
            _cputype=arm
        fi
    fi
 
    _arch="${_cputype}-${_ostype}"
 
    RETVAL="$_arch"
}
 
say() {
    printf 'rustup: %s\n' "$1"
}
 
err() {
    say "$1" >&2
    exit 1
}
 
need_cmd() {
    if ! check_cmd "$1"; then
        err "need '$1' (command not found)"
    fi
}
 
check_cmd() {
    command -v "$1" > /dev/null 2>&1
}
 
assert_nz() {
    if [ -z "$1" ]; then err "assert_nz $2"; fi
}
 
# Run a command that should never fail. If the command fails execution
# will immediately terminate with an error showing the failing
# command.
ensure() {
    if ! "$@"; then err "command failed: $*"; fi
}
 
# This is just for indicating that commands' results are being
# intentionally ignored. Usually, because it's being executed
# as part of error handling.
ignore() {
    "$@"
}
 
# This wraps curl or wget. Try curl first, if not installed,
# use wget instead.
downloader() {
    local _dld
    local _ciphersuites
    local _err
    local _status
    if check_cmd curl; then
        _dld=curl
    elif check_cmd wget; then
        _dld=wget
    else
        _dld='curl or wget' # to be used in error message of need_cmd
    fi
 
    if [ "$1" = --check ]; then
        need_cmd "$_dld"
    elif [ "$_dld" = curl ]; then
        get_ciphersuites_for_curl
        _ciphersuites="$RETVAL"
        if [ -n "$_ciphersuites" ]; then
            _err=$(curl --proto '=https' --tlsv1.2 --ciphers "$_ciphersuites" --silent --show-error --fail --location "$1" --output "$2" 2>&1)
            _status=$?
        else
            echo "Warning: Not enforcing strong cipher suites for TLS, this is potentially less secure"
            if ! check_help_for "$3" curl --proto --tlsv1.2; then
                echo "Warning: Not enforcing TLS v1.2, this is potentially less secure"
                _err=$(curl --silent --show-error --fail --location "$1" --output "$2" 2>&1)
                _status=$?
            else
                _err=$(curl --proto '=https' --tlsv1.2 --silent --show-error --fail --location "$1" --output "$2" 2>&1)
                _status=$?
            fi
        fi
        if [ -n "$_err" ]; then
            echo "$_err" >&2
            if echo "$_err" | grep -q 404$; then
                err "installer for platform '$3' not found, this may be unsupported"
            fi
        fi
        return $_status
    elif [ "$_dld" = wget ]; then
        get_ciphersuites_for_wget
        _ciphersuites="$RETVAL"
        if [ -n "$_ciphersuites" ]; then
            _err=$(wget --https-only --secure-protocol=TLSv1_2 --ciphers "$_ciphersuites" "$1" -O "$2" 2>&1)
            _status=$?
        else
            echo "Warning: Not enforcing strong cipher suites for TLS, this is potentially less secure"
            if ! check_help_for "$3" wget --https-only --secure-protocol; then
                echo "Warning: Not enforcing TLS v1.2, this is potentially less secure"
                _err=$(wget "$1" -O "$2" 2>&1)
                _status=$?
            else
                _err=$(wget --https-only --secure-protocol=TLSv1_2 "$1" -O "$2" 2>&1)
                _status=$?
            fi
        fi
        if [ -n "$_err" ]; then
            echo "$_err" >&2
            if echo "$_err" | grep -q ' 404 Not Found$'; then
                err "installer for platform '$3' not found, this may be unsupported"
            fi
        fi
        return $_status
    else
        err "Unknown downloader"   # should not reach here
    fi
}
 
check_help_for() {
    local _arch
    local _cmd
    local _arg
    _arch="$1"
    shift
    _cmd="$1"
    shift
 
    local _category
    if "$_cmd" --help | grep -q 'For all options use the manual or "--help all".'; then
      _category="all"
    else
      _category=""
    fi
 
    case "$_arch" in
 
        *darwin*)
        if check_cmd sw_vers; then
            case $(sw_vers -productVersion) in
                10.*)
                    # If we're running on macOS, older than 10.13, then we always
                    # fail to find these options to force fallback
                    if [ "$(sw_vers -productVersion | cut -d. -f2)" -lt 13 ]; then
                        # Older than 10.13
                        echo "Warning: Detected macOS platform older than 10.13"
                        return 1
                    fi
                    ;;
                11.*)
                    # We assume Big Sur will be OK for now
                    ;;
                *)
                    # Unknown product version, warn and continue
                    echo "Warning: Detected unknown macOS major version: $(sw_vers -productVersion)"
                    echo "Warning TLS capabilities detection may fail"
                    ;;
            esac
        fi
        ;;
 
    esac
 
    for _arg in "$@"; do
        if ! "$_cmd" --help $_category | grep -q -- "$_arg"; then
            return 1
        fi
    done
 
    true # not strictly needed
}
 
# Return cipher suite string specified by user, otherwise return strong TLS 1.2-1.3 cipher suites
# if support by local tools is detected. Detection currently supports these curl backends:
# GnuTLS and OpenSSL (possibly also LibreSSL and BoringSSL). Return value can be empty.
get_ciphersuites_for_curl() {
    if [ -n "${RUSTUP_TLS_CIPHERSUITES-}" ]; then
        # user specified custom cipher suites, assume they know what they're doing
        RETVAL="$RUSTUP_TLS_CIPHERSUITES"
        return
    fi
 
    local _openssl_syntax="no"
    local _gnutls_syntax="no"
    local _backend_supported="yes"
    if curl -V | grep -q ' OpenSSL/'; then
        _openssl_syntax="yes"
    elif curl -V | grep -iq ' LibreSSL/'; then
        _openssl_syntax="yes"
    elif curl -V | grep -iq ' BoringSSL/'; then
        _openssl_syntax="yes"
    elif curl -V | grep -iq ' GnuTLS/'; then
        _gnutls_syntax="yes"
    else
        _backend_supported="no"
    fi
 
    local _args_supported="no"
    if [ "$_backend_supported" = "yes" ]; then
        # "unspecified" is for arch, allows for possibility old OS using macports, homebrew, etc.
        if check_help_for "notspecified" "curl" "--tlsv1.2" "--ciphers" "--proto"; then
            _args_supported="yes"
        fi
    fi
 
    local _cs=""
    if [ "$_args_supported" = "yes" ]; then
        if [ "$_openssl_syntax" = "yes" ]; then
            _cs=$(get_strong_ciphersuites_for "openssl")
        elif [ "$_gnutls_syntax" = "yes" ]; then
            _cs=$(get_strong_ciphersuites_for "gnutls")
        fi
    fi
 
    RETVAL="$_cs"
}
 
# Return cipher suite string specified by user, otherwise return strong TLS 1.2-1.3 cipher suites
# if support by local tools is detected. Detection currently supports these wget backends:
# GnuTLS and OpenSSL (possibly also LibreSSL and BoringSSL). Return value can be empty.
get_ciphersuites_for_wget() {
    if [ -n "${RUSTUP_TLS_CIPHERSUITES-}" ]; then
        # user specified custom cipher suites, assume they know what they're doing
        RETVAL="$RUSTUP_TLS_CIPHERSUITES"
        return
    fi
 
    local _cs=""
    if wget -V | grep -q '\-DHAVE_LIBSSL'; then
        # "unspecified" is for arch, allows for possibility old OS using macports, homebrew, etc.
        if check_help_for "notspecified" "wget" "TLSv1_2" "--ciphers" "--https-only" "--secure-protocol"; then
            _cs=$(get_strong_ciphersuites_for "openssl")
        fi
    elif wget -V | grep -q '\-DHAVE_LIBGNUTLS'; then
        # "unspecified" is for arch, allows for possibility old OS using macports, homebrew, etc.
        if check_help_for "notspecified" "wget" "TLSv1_2" "--ciphers" "--https-only" "--secure-protocol"; then
            _cs=$(get_strong_ciphersuites_for "gnutls")
        fi
    fi
 
    RETVAL="$_cs"
}
 
# Return strong TLS 1.2-1.3 cipher suites in OpenSSL or GnuTLS syntax. TLS 1.2
# excludes non-ECDHE and non-AEAD cipher suites. DHE is excluded due to bad
# DH params often found on servers (see RFC 7919). Sequence matches or is
# similar to Firefox 68 ESR with weak cipher suites disabled via about:config.
# $1 must be openssl or gnutls.
get_strong_ciphersuites_for() {
    if [ "$1" = "openssl" ]; then
        # OpenSSL is forgiving of unknown values, no problems with TLS 1.3 values on versions that don't support it yet.
        echo "TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384"
    elif [ "$1" = "gnutls" ]; then
        # GnuTLS isn't forgiving of unknown values, so this may require a GnuTLS version that supports TLS 1.3 even if wget doesn't.
        # Begin with SECURE128 (and higher) then remove/add to build cipher suites. Produces same 9 cipher suites as OpenSSL but in slightly different order.
        echo "SECURE128:-VERS-SSL3.0:-VERS-TLS1.0:-VERS-TLS1.1:-VERS-DTLS-ALL:-CIPHER-ALL:-MAC-ALL:-KX-ALL:+AEAD:+ECDHE-ECDSA:+ECDHE-RSA:+AES-128-GCM:+CHACHA20-POLY1305:+AES-256-GCM"
    fi
}
 
main "$@" || exit 1