目次
Rust 関連
Rust (ラスト) は、性能、メモリ安全性、安全な並行性を目指して設計されたマルチパラダイムのプログラミング言語である。C 言語、C++ に代わるシステムプログラミング言語を目指しており、構文的にはC++に似ているが、「ボローチェッカー」(borrow checker) で参照の有効性を検証することによってメモリ安全性を保証できる。Rust はガベージコレクションなしでのメモリ安全性を達成しており、必要な場面で参照カウントを使うこともできる。
出典: Rust (プログラミング言語) - Wikiwand
本家: Rustプログラミング言語
Rust の日本語情報
ソースコード: The Rust Programming Language
ドキュメント: Rustを学ぶ/Rustプログラミング言語
Rustの日本語ドキュメント/Japanese Docs for Rust
The Rust Programming Language 日本語版 - The Rust Programming Language 日本語版 (日本語訳)
The Rust Programming Language 日本語版 (PDF版) (日本語訳)
The Rust Programming Language - The Rust Programming Language (公式英語)
関連文献
インストール
Linux
Fedora (Rust 公式から...)
公式(非公式日本語翻訳): インストール - The Rust Programming Language 日本語版 より
cargo、rustc、および、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 公式からのインストールで開発環境は整う🤔
cargo、rustc はインストールされるが、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
$ 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 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: setting default host triple to arm-unknown-linux-gnueabihf info: syncing channel updates for 'stable-arm-unknown-linux-gnueabihf' info: latest update on 2022-05-19, rust version 1.61.0 (fe5b13d68 2022-05-18) info: downloading component 'cargo' 5.9 MiB / 5.9 MiB (100 %) 570.1 KiB/s in 12s ETA: 0s info: downloading component 'clippy' 2.5 MiB / 2.5 MiB (100 %) 567.7 KiB/s in 5s ETA: 0s info: downloading component 'rust-docs' 19.7 MiB / 19.7 MiB (100 %) 741.7 KiB/s in 28s ETA: 0s info: downloading component 'rust-std' 23.5 MiB / 23.5 MiB (100 %) 666.3 KiB/s in 39s ETA: 0s info: downloading component 'rustc' 77.3 MiB / 77.3 MiB (100 %) 647.2 KiB/s in 2m 2s ETA: 0s info: downloading component 'rustfmt' 3.5 MiB / 3.5 MiB (100 %) 597.6 KiB/s in 6s ETA: 0s info: installing component 'cargo' 5.9 MiB / 5.9 MiB (100 %) 1.5 MiB/s in 4s ETA: 0s info: installing component 'clippy' 2.5 MiB / 2.5 MiB (100 %) 1.6 MiB/s in 2s ETA: 0s info: installing component 'rust-docs' 19.7 MiB / 19.7 MiB (100 %) 619.2 KiB/s in 1m 38s ETA: 0s info: installing component 'rust-std' 23.5 MiB / 23.5 MiB (100 %) 1.3 MiB/s in 19s ETA: 0s info: installing component 'rustc' 77.3 MiB / 77.3 MiB (100 %) 1.4 MiB/s in 57s ETA: 0s info: installing component 'rustfmt' 3.5 MiB / 3.5 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.61.0 (fe5b13d68 2022-05-18) Rust is installed now. Great! To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH environment variable. This has not been done automatically. 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
Windows
Visual Studio、Visual Studio Code を利用する場合は Windows で Rust 用の開発環境を設定する も参照。
以下は Scoop によるインストール手順です🤔
$ scoop install rustup
Installing 'rustup' (1.24.3) [64bit] rustup-init.exe (12.0 MB) [===================================================================================] 100% Checking hash of rustup-init.exe ... ok. Running installer script... info: profile set to 'default' info: setting default host triple to x86_64-pc-windows-gnu info: syncing channel updates for 'stable-x86_64-pc-windows-gnu' info: latest update on 2022-05-19, rust version 1.61.0 (fe5b13d68 2022-05-18) info: downloading component 'cargo' 7.0 MiB / 7.0 MiB (100 %) 3.0 MiB/s in 2s ETA: 0s info: downloading component 'clippy' 3.3 MiB / 3.3 MiB (100 %) 2.8 MiB/s in 1s ETA: 0s info: downloading component 'rust-docs' 19.6 MiB / 19.6 MiB (100 %) 2.4 MiB/s in 7s ETA: 0s info: downloading component 'rust-mingw' 4.2 MiB / 4.2 MiB (100 %) 2.8 MiB/s in 2s ETA: 0s info: downloading component 'rust-std' 25.3 MiB / 25.3 MiB (100 %) 3.6 MiB/s in 8s ETA: 0s info: downloading component 'rustc' 70.1 MiB / 70.1 MiB (100 %) 3.4 MiB/s in 20s ETA: 0s info: downloading component 'rustfmt' 6.2 MiB / 6.2 MiB (100 %) 3.1 MiB/s in 2s ETA: 0s info: installing component 'cargo' info: installing component 'clippy' info: installing component 'rust-docs' 19.6 MiB / 19.6 MiB (100 %) 912.0 KiB/s in 38s ETA: 0s info: installing component 'rust-mingw' info: installing component 'rust-std' 25.3 MiB / 25.3 MiB (100 %) 6.8 MiB/s in 4s ETA: 0s info: installing component 'rustc' 70.1 MiB / 70.1 MiB (100 %) 6.8 MiB/s in 10s ETA: 0s info: installing component 'rustfmt' 6.2 MiB / 6.2 MiB (100 %) 4.9 MiB/s in 1s ETA: 0s info: default toolchain set to 'stable-x86_64-pc-windows-gnu' stable-x86_64-pc-windows-gnu installed - rustc 1.61.0 (fe5b13d68 2022-05-18) Rust is installed now. Great! 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. Linking ~\scoop\apps\rustup\current => ~\scoop\apps\rustup\1.24.3 Persisting .cargo Persisting .rustup 'rustup' (1.24.3) was installed successfully! 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
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.24.3", "description": "Manage multiple rust installations with ease", "homepage": "https://rustup.rs", "license": "MIT|Apache-2.0", "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", "architecture": { "64bit": { "url": "https://static.rust-lang.org/rustup/archive/1.24.3/x86_64-pc-windows-gnu/rustup-init.exe", "hash": "5a4e8d6193f4239cd81c02350949c73b6ce4ac52839d204f9552a132b552cc41" }, "32bit": { "url": "https://static.rust-lang.org/rustup/archive/1.24.3/i686-pc-windows-gnu/rustup-init.exe", "hash": "89f529d6e17d688bf5f2c2af25281da504c24830c794564287bf760c0e6e2e9b" } }, "installer": { "script": [ "[Environment]::SetEnvironmentVariable('CARGO_HOME', \"$persist_dir\\.cargo\", 'Process')", "[Environment]::SetEnvironmentVariable('RUSTUP_HOME', \"$persist_dir\\.rustup\", 'Process')", "$host_arch = if ($architecture -eq '64bit') {'x86_64'} else {'i686'}", "Invoke-ExternalCommand -Path \"$dir\\rustup-init.exe\" -Args \"-y --no-modify-path --default-host $host_arch-pc-windows-gnu\" | 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-gnu/rustup-init.exe" }, "32bit": { "url": "https://static.rust-lang.org/rustup/archive/$version/i686-pc-windows-gnu/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.61.0 (fe5b13d68 2022-05-18)
$ cargo --version
cargo 1.61.0 (a028ae42f 2022-04-29)
Android (Termux!)
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!🤤
Cargo ではるおわ〜るどする😆
参考: Hello, Cargo! - The Rust Programming Language 日本語版
Cargo のバージョンが表示されれば利用出来る状態になっていることが確認できる🤔
$ cargo --version
cargo 1.65.0 (4bc8f24d3 2022-10-20)
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/tomoyan/my_projects/haruo_cargo) Finished dev [unoptimized + debuginfo] target(s) in 4.34s Running `target/debug/haruo_cargo` Haruo, world!
Rust の更新
公式: 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-updates info: downloading self-update rustup updated - 1.25.1 (from 1.24.3)
$ rustup -V
rustup 1.25.1 (bb60b1e89 2022-07-12) info: This is the version for the rustup toolchain manager, not the rustc compiler. info: The currently active `rustc` version is `rustc 1.61.0 (fe5b13d68 2022-05-18)`
rust の更新を行う🤔
$ rustup update
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu' info: latest update on 2022-11-03, rust version 1.65.0 (897e37553 2022-11-02) info: downloading component 'rust-src' info: downloading component 'cargo' 6.5 MiB / 6.5 MiB (100 %) 5.0 MiB/s in 1s ETA: 0s info: downloading component 'clippy' 2.9 MiB / 2.9 MiB (100 %) 2.7 MiB/s in 1s ETA: 0s info: downloading component 'rust-docs' 18.8 MiB / 18.8 MiB (100 %) 3.2 MiB/s in 6s ETA: 0s info: downloading component 'rust-std' 30.0 MiB / 30.0 MiB (100 %) 582.4 KiB/s in 16s ETA: 0s info: downloading component 'rustc' 56.2 MiB / 56.2 MiB (100 %) 1.2 MiB/s in 53s ETA: 0s info: downloading component 'rustfmt' 4.3 MiB / 4.3 MiB (100 %) 1.3 MiB/s in 3s ETA: 0s 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-src' info: installing component 'cargo' info: installing component 'clippy' info: installing component 'rust-docs' 18.8 MiB / 18.8 MiB (100 %) 4.1 MiB/s in 4s ETA: 0s info: installing component 'rust-std' 30.0 MiB / 30.0 MiB (100 %) 5.5 MiB/s in 5s ETA: 0s info: installing component 'rustc' 56.2 MiB / 56.2 MiB (100 %) 7.8 MiB/s in 11s ETA: 0s info: installing component 'rustfmt' info: checking for self-updates stable-x86_64-unknown-linux-gnu updated - rustc 1.65.0 (897e37553 2022-11-02) (from rustc 1.63.0 (4b91a6ea7 2022-08-08)) info: cleaning up downloads & tmp directories
ツールチェイン (toolchain)
デフォルトのツールチェインを確認する🤔
$ 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)
クロスビルド可能なターゲットの一覧を表示する🤔
※ターゲットトリプル: {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
インストール
クロスビルド可能なターゲットの一覧に存在するものは、ターゲットを追加するだけで済みます😊
$ rustup target add thumbv7em-none-eabihf
info: downloading component 'rust-std' for 'thumbv7em-none-eabihf' info: installing component 'rust-std' for 'thumbv7em-none-eabihf' 10.4 MiB / 10.4 MiB (100 %) 8.2 MiB/s in 1s ETA: 0s
$ rustup show Default host: x86_64-unknown-linux-gnu rustup home: /home/tomoyan/.rustup installed targets for active toolchain -------------------------------------- thumbv7em-none-eabihf x86_64-unknown-linux-gnu active toolchain ---------------- stable-x86_64-unknown-linux-gnu (default) rustc 1.65.0 (897e37553 2022-11-02)
アンインストール
$ 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)
sccache - Shared Compilation Cache
ソースコード: 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-toolchainpackage 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"
Evcxr
トラブルシューティング
[sccache] error: failed to run custom build command for `openssl-sys v0.9.75` でビルドがエラー終了する
$ 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 完了しました!
[sccache] No space left on device (os error 28) でビルドがエラー終了する
$ 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 ...
Rust のアンインストール
$ 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 info: removing rustup home info: removing cargo home info: removing rustup binaries info: rustup is uninstalled
参考文献
scoopで作るRustのWindows開発環境 - Qiita
Rustをインストールして、Hello Worldしただけの話 - matobaの備忘録
インストール後にrustupを使ってすること|WindowsでRustの開発環境を構築する(not on WSL)/おまけのみ有料
Rustでreplやjupyter-notebook使う
コンパイルキャッシュでRustのビルド時間を短縮しよう - Qiita
Rust プロジェクトの GitHub Actions で incremental build をするためのテクニック
Rust でクロスコンパイルして Raspberry Pi Zero W で動かす - Qiita
Ubuntu上でRaspberry Pi Zero向けクロスコンパイル事始め - Qiita
Rust - ArchWiki
Introduction - The Rust on ESP Book
付録
インストーラスクリプトの内容
$ 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