Is cargo dependency resolution algorithm documented?

I have to replicate cargo's dependency resolution algorithm in a different programming language but I could not find documentation explaining how cargo build the dependency tree.

My current implementation is:

  1. Download crate index file from
  2. Get list of dependencies, and its version requirements and store into a table crate X requirements
  3. For each dependency, find in the index the crate version that satisfies the requirements
  4. For each dependency, repeat the process, recursively, while accumulating the requirements on the "crate X requirements" for the next iteration

This algorithm is not producing the same output as running cargo, and is also finding several conflicts.

The source code for Cargo has a good description of the algorithm in its comments:


Cargo's resolver is very complex. AFAIK the resolver is not documented completely and coherently in a single document. As @hax10 pointed out, you probably should look into the resolver module. You can find the source code here:

and I'd use the developer version of the documentation, as it contains private items and submodules which may be of interest to you:


Yes. I did check the documentation, but it is not very helpful IMHO.

Tried browsing around the code as well, but I could not track the process across the different source files.

There was an effort to move Cargo to the PubGrub dependency resolution algorithm precisely because the current method has a lot of edge cases. I'm not sure of the current status though. GitHub - pubgrub-rs/pubgrub: PubGrub version solving algorithm implemented in Rust

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.