Help: cargo package with Github dependencies

Hi there!

I am building a project that is organized in the following structure:

  • A main repo (called "api"), hosted on Github
  • Multiple submodules, each hosted in their own Github repo and linked to the main repo under a modules/ directory, as well as on a .gitmodules file

The main repo has 2 of these submodules as direct dependencies. The submodules also have dependencies among themselves (they're not independent pieces).

Example: Cargo.toml from the main repo

...
[dependencies]
api_auth = { git = "https://github.com/name/api_auth.git", version = "0.1.0", optional = true }
api_extensions = { git = "https://github.com/name/api_extensions.git", version = "0.1.0" }

Now I am trying to build and package the main repo into a tarball.

I ran cargo build, then cargo package.

Unfortunately, cargo package fails me with the error:

error: failed to prepare local package for uploading

Caused by:
  no matching package named `api_auth` found
  location searched: registry `crates-io`
  required by package `api v0.1.0

I understand that it is looking for the api_auth submodule on crates-io, but it shouldn't, as I have specified that it is on Github.

I only added the version = "0.1.0" on the two Git dependencies because before that, it was throwing me another error saying that all dependencies need versions.

Can you help me? Thanks!

Note: I need to host all of these things on Github instead of crates.io because they need to be private.

While packaging and publishing, git dependency overrides are ignored. I don't think this is possible to do as-is. See the note at the end of this section:

Note : crates.io does not allow packages to be published with git dependencies (git dev-dependenciesare ignored). See the Multiple locationssection for a fallback alternative.

What's the goal here?

I ask, because if

means that you plan on fetching these dependencies from Github in downstream projects, then there's no need to package them - Cargo will happily fetch the Git repository itself as a dependency.

cargo package is for distributing packages into a registry, generally, but you don't need to run a registry to have private packages.

Thank you @H2CO3 and @derspiny!

Based on your replies, I decided to switch the architecture of the project and have now been able to accomplish what I wanted by putting it all within one repo, structured into multiple crates, each with its own version specified for packaging.