Rust development notes

by R. S. Doiel, 2022-09-27

I recently wanted to try ncgopher which is a rust based application. I was working on a an M1 Mac mini. I use Mac Ports for my userland applications and installed cargo to pickup the rust compiler and build tool

  1. sudo port install cargo

All went well until I tried to build ncgopher and got an error as follows

  1. cargo build --release
  2. Updating crates.io index
  3. error: Unable to update registry `crates-io`
  4. Caused by:
  5. failed to fetch `https://github.com/rust-lang/crates.io-index`
  6. Caused by:
  7. failed to authenticate when downloading repository: git@github.com:rust-lang/crates.io-index
  8. * attempted ssh-agent authentication, but no usernames succeeded: `git`
  9. if the git CLI succeeds then `net.git-fetch-with-cli` may help here
  10. https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
  11. Caused by:
  12. no authentication available
  13. make: *** [build] Error 101

This seemed odd as I could run git clone git@github.com:rust-lang/crates.io-index successfully. Re-reading the error message a dim light went on. I checked the cargo docs and the value net.git-fetch-with-cli defaults to false. That meant that cargo was using its own embedded git. OK, that makes sense but how do I fix it. I had no problem using cargo installed via ports on an Intel iMac so what gives? When cargo got installed on the M1 there was now .cargo/config.toml file. If you create this and set the value of git-fetch-with-cli to true then the problem resolves itself.

It was good that the error message provided a lead. It’s also good that cargo has nice documentation. My experience though still left the taste of COIK. Not sure how to improve the situation. It’s not really a cargo bug (unless config.taml should be always created), it’s not a rust bug and I don’t even think it is a ports packaging bug. If I was a new developer just getting familiar with git I don’t think I would have known how to solve my problem even with the documentation provided. Git is something that has always struggled with COIK. While I like it it does make things challenging.

If I wind up playing with rust more then I’ll add somemore notes here in the future.

My $HOME/.cargo/config.toml file looks like to have cargo use the git cli instead of the built in rust library.

  1. [net]
  2. git-fetch-with-cli = true