Gentoo Linux環境にportageのrustupを入れる

2021/01/22 11:34#Gentoo#Rust

Gentooを使っています。
rustupが必要になったのでパッケージがあるか調べたらありました。
https://packages.gentoo.org/packages/dev-util/rustup

$ echo "dev-util/rustup ~amd64" >> /etc/portage/package.accept_keywords
$ emerge -a rustup
$ rustup --help
fish: Unknown command: rustup

emerge -a rustupしただけでは使えないみたいです。
代わりにrustup-initコマンドが入っていたのですが、Gentoo環境だと既にRustが入っているのでこうです。

$ rustup-init
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.
error: cannot install while Rust is installed

Continue? (y/N)

さらに変わりにrustup-init-gentooコマンドが入っていました。
きっとこれです。

$ rustup-init-gentoo --help
Usage: /usr/bin/rustup-init-gentoo [<options>]

Symlink system installation of rustup to /home/garypippi/.cargo

Options:
	-a, --apply	Apply changes (required)
	-C, --nocolor	Disable colored output
	-d, --debug	Debug mode (sets -x shell option)
	-V, --version	Print version number
	-q, --quiet	Quiet mode

言うとおりに反映してみます。

$ rustup-init-gentoo -a
'/home/garypippi/.cargo/bin/cargo' -> '/usr/bin/rustup-init'
'/home/garypippi/.cargo/bin/cargo-clippy' -> '/usr/bin/rustup-init'
'/home/garypippi/.cargo/bin/cargo-fmt' -> '/usr/bin/rustup-init'
'/home/garypippi/.cargo/bin/cargo-miri' -> '/usr/bin/rustup-init'
'/home/garypippi/.cargo/bin/clippy-driver' -> '/usr/bin/rustup-init'
'/home/garypippi/.cargo/bin/rls' -> '/usr/bin/rustup-init'
'/home/garypippi/.cargo/bin/rustc' -> '/usr/bin/rustup-init'
'/home/garypippi/.cargo/bin/rustdoc' -> '/usr/bin/rustup-init'
'/home/garypippi/.cargo/bin/rustfmt' -> '/usr/bin/rustup-init'
'/home/garypippi/.cargo/bin/rust-gdb' -> '/usr/bin/rustup-init'
'/home/garypippi/.cargo/bin/rust-lldb' -> '/usr/bin/rustup-init'
'/home/garypippi/.cargo/bin/rustup' -> '/usr/bin/rustup-init'
* Setting gentoo rust-1.48.0 as default toolchain
rustup 1.23.0 (2021-01-22)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.48.0`
verbose: read metadata version: '12'
verbose: updating existing install for 'gentoo'
verbose: toolchain directory: '/home/garypippi/.rustup/toolchains/gentoo'
verbose: removing install directory: '/home/garypippi/.rustup/toolchains/gentoo'
verbose: linking directory from: '/home/garypippi/.rustup/toolchains/gentoo'
verbose: toolchain 'gentoo' installed
verbose: read metadata version: '12'
info: default toolchain set to 'gentoo'
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/garypippi/.rustup

gentoo (default)
rustc 1.48.0
* Prepend /home/garypippi/.cargo/bin to your PATH to use rustup
* rustup selfupdate is disabled, it will be updated by portage

~/.cargoいろいろリンク貼られました。
PATH追加せよとのことです。

$ echo "set -xa PATH ~/.cargo/bin" >> ~/.config/fish/config.fish
$ fish -p ~/.config/fish/config.fish
$ rustup -V
rustup 1.23.0 (2021-01-22)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.48.0`

rlsインストールしたかったのでやってみます。

$ rustup component add rls rust-analysis rust-src
error: gentoo is a custom toolchain

Rustのことがよくわかっていないのですが、toolchainことで怒られているみたいです。
通常のものをいれてみます。

$ rustup toolchain list
gentoo (default)

$ rustup toolchain install stable
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2020-12-31, rust version 1.49.0 (e1884a8e3 2020-12-29)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
 55.7 MiB /  55.7 MiB (100 %)  40.5 MiB/s in  1s ETA:  0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: using up to 500.0 MiB of RAM to unpack components
info: installing component 'clippy'
info: installing component 'rust-docs'
 13.8 MiB /  13.8 MiB (100 %)  12.1 MiB/s in  1s ETA:  0s
info: installing component 'rust-std'
 22.3 MiB /  22.3 MiB (100 %)  14.6 MiB/s in  1s ETA:  0s
info: installing component 'rustc'
 55.7 MiB /  55.7 MiB (100 %)  15.3 MiB/s in  3s ETA:  0s
info: installing component 'rustfmt'

  stable-x86_64-unknown-linux-gnu installed - rustc 1.49.0 (e1884a8e3 2020-12-29)

結局、システム以外のrustcが入ってしましましたが、rlsは使えるようになりました。