環境
WSL2 Ubuntu20.04
cargo 1.50.0 (f04e7fab7 2021-02-04)
rustc 1.50.0 (cb75ad5db 2021-02-10)
エラーが出た場面
Rustのチュートリアルの「数当てゲームをプログラムする (https://doc.rust-jp.rs/book-ja/ch02-00-guessing-game-tutorial.html) 」で、Cargo.tomlのdependenciesに
[dependencies]
rand = "0.3.14"
と追記し、cargo buildを実行した際に発生。
$ cargo build
Updating crates.io index
warning: spurious network error (2 tries remaining): failed to mmap. Could not write data: Permission denied; class=Os (2)
warning: spurious network error (1 tries remaining): failed to mmap. Could not write data: Permission denied; class=Os (2)
error: failed to get `rand` as a dependency of package `guessing_game v0.1.0 (/path/to/guessing_game)`
Caused by:
failed to load source for dependency `rand`
Caused by:
Unable to update registry `https://github.com/rust-lang/crates.io-index`
Caused by:
failed to fetch `https://github.com/rust-lang/crates.io-index`
Caused by:
failed to mmap. Could not write data: Permission denied; class=Os (2)
解決方法
~/.cargo/config内に、以下の内容を追記
ファイルが無ければ作成して記述する。
[net]
git-fetch-with-cli = true
git-fetch-with-cliとは
リファレンスにはこう記載されている。
If this is true, then Cargo will use the git executable to fetch registry indexes and git dependencies. If false, then it uses a built-in git library.
Setting this to true can be helpful if you have special authentication requirements that Cargo does not support. See Git Authentication for more information about setting up git authentication.
要は、デフォルトのfalse状態だと組み込みのgitライブラリを使用してレジストリとgitの依存関係を取得するけど、trueにするとライブラリではなくgitの実行ファイルを直接叩いて行うよ、的なことを言っているみたいです。
参考資料