Stable way of getting registry index data?

I have a project which uses cargo metadata to look up information about a crate's dependency tree. I seem to be falling into a gap between what's in the local copy of the index, and what's exposed through cargo metadata.

In particular, I'm looking to get the cksum for the crate's deps. AFAICT cargo metadata doesn't return this.

I found https://github.com/ehuss/cargo-index/tree/master/reg-index which implements this functionality for non-bare indexes, but it appears to assume that the working directory has materialised with a view of of a ref, rather than going via the git APIs which cargo itself appears to do since https://github.com/rust-lang/cargo/pull/4026. I'd be happy to add bare git support if it could be implemented in a way which should continue working in the future.

A few specific questions:

  1. Is there an easy way of getting the cksum of a crate which I've overlooked, ideally using local data?
  2. How stable is the git directory location, layout, and object format intended to be? AFAICT cargo metadata yields a manifest_path along the lines of ~/.cargo/registry/src/github.com-1ecc6299db9ec823/itoa-0.4.6/Cargo.toml and that can be trivially transformed into ~/.cargo/registry/index/github.com-1ecc6299db9ec823 where you can git show origin/master:it/oa/itoa which yields JSON-per-version. Which of these things is it reasonable to rely on?

Updating reg-index to support bare repositories sounds like a worthwhile improvement. I would also be open to to discussing adding cksum to cargo metadata. The index is stable, we will always provide it in this format even if future Cargos does something new and fancy, so as to support past Cargos.

Weather Cargo checks out the index and where is an implementation detail, but not one that is likely to change mutch. There is a unapproved eRFC to switch to serving it over HTTP, but it is not making much progress. There is some discussion of moving Cargo_Home to a more system appropriate location, but not much is actually happening. The hash value does change sometimes. When it is straightforward, we try to keep it so as not to make people download the index again. But it does change sometimes.

2 Likes

You can get checksum via https://lib.rs/crates/crates-index

1 Like