'cargo publish' to a private git repository?

I'm trying to use 'cargo publish' to a private registry which uses 'git' (I need to use the dependency a coming from a registry and not directly using the git url as otherwise I have other issues with specifying versions which I cannot do if I refer to the dependency using git url).
I've added a [registry.myregistry] section in .cargo/config.toml of my project, containing the 'index' property pointing to my git repository I plan to use as a registry.

Whenever I run 'cargo publish', I get the following issues:

cargo publish -vvvv -p my_package                                                                                                                                                                           
    Updating `myregistry` index
     Running `git fetch --verbose --force --update-head-ok 'https://...../myregistry.git' '+HEAD:refs/remotes/origin/HEAD'`
POST git-upload-pack (321 bytes)
From https://..../myregistry.git
 = [up to date]                 -> origin/HEAD
thread 'main' panicked at 'remote registries must have config', src/cargo/ops/registry/mod.rs:135:13

looks like I'm missing some registry configuration on my side but I can't find what it is.
Does anybody know what is the "remote registry config" cargo publish is complaining about?

Unfortunately you need more than a git repo to host a registry you can publish to (you need a server to host the .crate compressed files and must provide a web api as well). Here's a reference on how to run your own registry and what resources you must provide: Running a Registry - The Cargo Book. If that's too much work for you, you can use a service that hosts private registries for you, like cloudsmith for example.

1 Like

thanks!

Indeed, after some more tinkering it looks like the "missing config" message is not so much "client not having the config" but "registry not exposing its config". cargo is looking for a config.json file where api endpoint and other stuff is configured.

Kellnr is a free and open-source registry for Rust crates. It functions similarly to crates.io, but with the added benefit of being able to host it on your own hardware for private crates.

2 Likes

Full list of alternative registries: Third party registries · rust-lang/cargo Wiki · GitHub

And I'd recommend ktra if you want all your data (index repo & source code of packages & accounts) to be self-hosted.

5 Likes