Cargo config - alternate registry and "checksums"

So I am trying to setup my own private cargo server (crates.io-index mirror) in a closed environment.

My ${CARGO_HOME}/config.toml reads as follows

cat ~/.cargo/config.toml
[net]
# it only works with the git-cli, the libgit2 does not work for  us.
git-fetch-with-cli = true

[source]

[source.mirror]
git="ssh://git@gitlab.COMPANY.local/pure-testing/duane_cargo_index.git"
branch="master"

[source.crates-io]
replace-with = "mirror"

STEP 1: I create a new project with the command:

cargo new --bin foobar

STEP 2: I try to add 'libc' to the project and it fails with this error message:

   cd foobar
   cargo add libc

I get this error message:

$ cargo add libc
error: failed to load source for dependency `libc`

Caused by:
  Unable to update registry `crates-io`

Caused by:
  cannot replace `crates-io` with `mirror`, the source `crates-io` supports checksums, but `mirror` does not

  a lock file compatible with `crates-io` cannot be generated in this situation

My goal here is this: It is my understanding that the "crates.io-index" MUST be served from a GIT server only so I have put it in our gitlab server, and it is in the "master" branch, hence the "branch=master" in the cargo/config.toml file.

This is so fustrating .. I have not found an example that just works.

The Cargo documentation is misleading about this.

The git source is not related to registries at all. It's not even usable as a data source. It only exists to specify which git-based dependencies in Cargo.toml get replaced with local copies when using cargo vendor. It supports branch to match values of branch in Cargo.toml, not to actually use git.

For fetching of the entire registry with many crates over the git protocol, you must use the registry source type.

The registry = "url" is assumed to be a URL to a git repository, when it's not prefixed with sparse+https:// protocol. It doesn't support branch selection.

crates.io stopped using git-based registry and moved to sparse+https:// protocol, so the git-based registry support in Cargo doesn't get much attention these days. The sparse protocol is just a bunch of static files, so consider using it if you can serve your registry mirror over HTTP.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.