rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.7k stars 2.41k forks source link

Cargo run is failing with "failed to set hostkey preference: The requested method(s) are not currently supported; class=Ssh" #14617

Open fabioz opened 2 weeks ago

fabioz commented 2 weeks ago

Problem

I was trying to build the zed editor following instructions from: https://github.com/zed-industries/zed/blob/main/docs/src/development/windows.md

When I get to the cargo run phase the process fails with the message below:

λ cargo run
    Updating crates.io index
    Updating git repository `https://github.com/kvark/blade`
error: failed to get `blade-graphics` as a dependency of package `gpui v0.1.0 (X:\zedws\zed\crates\gpui)`

Caused by:
  failed to load source for dependency `blade-graphics`

Caused by:
  Unable to update https://github.com/kvark/blade

Caused by:
  failed to fetch into: C:\Users\<username>\.cargo\git\db\blade-b2bcd1de1cf7ab6a

Caused by:
  network failure seems to have happened
  if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  failed to set hostkey preference: The requested method(s) are not currently supported; class=Ssh (23)

I can manually git clone that repository:

λ git clone  https://github.com/kvark/blade
Cloning into 'blade'...
remote: Enumerating objects: 5129, done.
remote: Counting objects: 100% (895/895), done.
remote: Compressing objects: 100% (380/380), done.
remote: Total 5129 (delta 604), reused 557 (delta 512), pack-reused 4234 (from 1)
Receiving objects: 100% (5129/5129), 5.00 MiB | 4.02 MiB/s, done.
Resolving deltas: 100% (3287/3287), done.

But I don't know why cargo can't (which makes the build fail). I tried changing the cargo toml from ssh to https so that it becomes:

blade-graphics = { git = "ssh://git@github.com/kvark/blade" }

But it still fails with a very similar message:

 λ cargo run
    Updating crates.io index
    Updating git repository `ssh://git@github.com/kvark/blade`
error: failed to get `blade-graphics` as a dependency of package `gpui v0.1.0 (X:\zedws\zed\crates\gpui)`

Caused by:
  failed to load source for dependency `blade-graphics`

Caused by:
  Unable to update ssh://git@github.com/kvark/blade

Caused by:
  failed to fetch into: C:\Users\fabio\.cargo\git\db\blade-88a49619c2e97d2a

Caused by:
  network failure seems to have happened
  if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  failed to set hostkey preference: The requested method(s) are not currently supported; class=Ssh (23)

Steps

Follow the steps from https://github.com/zed-industries/zed/blob/main/docs/src/development/windows.md on Windows

Possible Solution(s)

No response

Notes

I'm on Windows. The git version on the system is:

set git
git_executable=C:\Program Files\Git\cmd\git.exe
GIT_INSTALL_ROOT=C:\Program Files\Git
git_locale="C:\Program Files\Git\usr\bin\locale.exe"
GIT_SSH=PLINK.exe
GIT_VERSION_USER=2.39.0.windows.1

I tried unsetting GIT_SSH and it didn't make any difference (not sure if cargo actually uses my system git -- probably not otherwise it'd probably work).

I don't really have any proxies that need to be set.

Version

λ cargo version --verbose cargo 1.81.0 (2dbb1af80 2024-08-20) release: 1.81.0 commit-hash: 2dbb1af80a2914475ba76827a312e29cedfa6b2f commit-date: 2024-08-20 host: x86_64-pc-windows-msvc libgit2: 1.8.1 (sys:0.19.0 vendored) libcurl: 8.8.0-DEV (sys:0.4.73+curl-8.8.0 vendored ssl:Schannel) os: Windows 10.0.22631 (Windows 11 Professional) [64-bit]

epage commented 2 weeks ago

Did you try the suggested workaround? What is the result?

Caused by: network failure seems to have happened if a proxy or similar is necessary `net.git-fetch-with-cli` may help here https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli 

We use libgit2 for most operations but allow overriding that with git in for fetch operations.

Do you have any special configuration in your .gitconfig or any unusual network setup?

weihanglo commented 2 weeks ago

Might be related https://github.com/libgit2/libgit2/issues/6612

fabioz commented 2 weeks ago

It's weird, I tried (in Windows) to add the config file to %USERPROFILE%\.cargo\config.toml with:

[net]
git-fetch-with-cli = true   # use the `git` executable for git operations

And it didn't work (I even double-checked that pasting that to the explorer opens the proper file).

Now, after trying with cargo --config net.git-fetch-with-cli=true run it did work, so, it seems that for some reason it's not picking up the cargo config, but at least I now have a workaround ;)

Do you have any special configuration in your .gitconfig or any unusual network setup?

I cleared my .gitconfig (except for the [user]) and got the same results and I don't think there's anything unusual in my network setup.

Might be related https://github.com/libgit2/libgit2/issues/6612

In the comments there's an issue that's exactly the same as mine: https://github.com/libgit2/libgit2/issues/6612#issuecomment-2171676893 (using cargo too, but no dice on the fix or reason).

weihanglo commented 2 weeks ago

Yeah, it seems like an upstream issue in libssh2: https://github.com/libgit2/libgit2/issues/6612#issuecomment-1662009380.

In order to track the process in upstream, I'll keep this open and marked as S-blocked-external.