Querying Cargo Dependency DAGs with Guppy
guppy
is a rust crate that provides tools for working with cargo dependency graphs using the petgraph
graph data structure crate. It’s used by Facebook to audit a high-security subset of the cargo dependency graph for some of their more high-visibility projects. Treating the dependency graph resulting from a cargo build operation as a DAG lets us draw on the well-studied field of graph algorithms to answer complex questions about our build without resorting to ad-hoc traversals or re-implementation of common graph primitives.
For my first project using guppy
, I decided to build a tool to produce machine-readable summaries describing why some target dependency is included in a cargo workspace’s build graph. My motivation was to support projects that are migrating from futures 0.1
to futures 0.3
. Many rust projects started using futures 0.1
for their initial async implementation, and are still in the process of switching over to futures 0.3
. If you’re interested in learning more about the differences between the two packages, this blog post by ncameron is a great resource. Being able to easily generate machine-readable reports opens up new possibilities - for example, you could use the output of this tool to build a linter that asserts that no new transitive dependencies on futures 0.1
are introduced into a workspace, to provide tooling-backed assurances that usage of futures 0.1
only ever decreases.