rust-lang / cargo

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

Failed to update git submodule of dependency #9622

Open saruman9 opened 3 years ago

saruman9 commented 3 years ago

Problem

Cargo can't clone/update a git submodule of dependency, for example redbpf crate, which contains submodule libbpf.

Steps

  1. cargo new cargo_issue_git_submodule
  2. cd cargo_issue_git_submodule
  3. echo 'redbpf = { git = "https://github.com/foniod/redbpf" }' >> Cargo.toml
  4. cargo check

And we will get an error:

error: failed to get `redbpf` as a dependency of package `cargo_issue_git_submodule v0.1.0 (/home/user/cargo_issue_git_submodule)`

Caused by:
  failed to load source for dependency `redbpf`

Caused by:
  Unable to update https://github.com/foniod/redbpf

Caused by:
  failed to update submodule `bpf-sys/libbpf`

Caused by:
  object not found - no match for id (5a10cd2060c19959e2c55ee33421baa358c09c0b); class=Odb (9); code=NotFound (-3)

Possible Solution(s)

Update submodule manually in ~/.cargo/git/checkouts/redbpf-HASH/b81f069/bpf-sys/libbpf.

Notes

cargo version: cargo 1.55.0

commit of cargo: 4c27c96645e235d81f6c8dfff03ff9ebaf0ef71d

ehuss commented 3 years ago

It looks like the commit 5a10cd2060c19959e2c55ee33421baa358c09c0b does not exist on any branch or tag in the repository https://github.com/redsift/libbpf.git. The way cargo fetches submodules needs to assume that it exists on some branch or tag.

Unfortunately I can't find any APIs in libgit2 that provide a way to fetch a specific commit, so I don't see a direct way this can be supported. One option is to restructure the net.git-fetch-with-cli option so that it uses git submodule update --init instead of git fetch (or pass the direct revision to git fetch which is supported as of git 2.5 — the server needs to support uploadpack.allowReachableSHA1InWant, which has been around since 2015 (I think), which I think is safe to assume everyone supports nowadays).

daniel-brenot-apcapital commented 2 years ago

This is something i'm currently running into that i'd really like to see resolved. At the current moment this is making it so that a submodule of one of my dependencies must be on the main/master branch, and that's not exactly doable