Code Monkey home page Code Monkey logo

cargo-depgraph's Introduction

cargo-depgraph

Creates dependency graphs for cargo projects using cargo metadata and graphviz.

Installation

cargo install cargo-depgraph

If you are using Arch Linux, you can alternatively install via pacman -S cargo-depgraph.

Usage

Note: This assumes you have Graphviz installed. There are also online tools that can generate graphics from the textual graphviz graphs cargo depgraph generates, if the command-line graphviz tools like dot aren't your thing.

cargo depgraph [options] | dot -Tpng > graph.png

The full list of options can be seen by running

cargo depgraph --help

Commonly useful options:

  • --all-deps

cargo-depgraph's dependency graph

  • --all-deps --dedup-transitive-deps

cargo-depgraph's dependency graph with transitive dependency edges de-duplicated

Output explanation

  • square node = root / workspace member
  • grey background = target-specific dependency
  • dotted lines = optional dependency (could be removed by disabling a cargo feature)
  • dashed lines = transitively optional dependency (could be removed by removing one of the dotted edges)
  • line colors = dependency kinds w.r.t. root / workspace members
    • black = normal
    • blue = dev-dependency
    • green = build-dependency
    • light turquoise = build-dependency of a dev-dependency
    • dark green = both normal and build-dependency
    • violet = both dev-dependency and build-dependency
    • … not seen in the wild yet, but theoretically possible:
      • dark turquoise = both normal and build-dependency of a dev-dependency
      • pastel blue = both dev-dependency and build-dependency of a dev-dependency
    • red = you broke it

cargo-depgraph's People

Contributors

bennd avatar jplatte avatar nathan-at-least avatar orhun avatar ragnargrootkoerkamp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cargo-depgraph's Issues

Add subgraph support

TBD:

  • Will there be a subgraph for the workspace members by default (could be named after the parent directory for example)
  • What about multiple subgraphs?
    • In general, I'm not sure whether to mirror cargo-deps' CLI for this feature

Add an option to show feature names

… on optional dependency edges.

With graphviz's png renderer and dot layouting, this will probably not look good, but maybe it works for other layouts.

Add an option to show cfg expressions

… on target-specific dependency edges.

With graphviz's png renderer and dot layouting, this will probably not look good, but maybe it works for other layouts.

Crash with stack overflow

This is reproduced with this repository / crate:

https://gitlab.freedesktop.org/libopenraw/libopenraw.git

(I'm the developer for that crate)

cargo-depgraph 1.6.0

$ cargo depgraph --all-deps
thread 'main' has overflowed its stack
fatal runtime error: stack overflow
zsh: IOT instruction (core dumped)  cargo depgraph --all-deps

In gdb

Program received signal SIGSEGV, Segmentation fault.
0x000055555557c6c9 in cargo_depgraph::graph::update_node ()
(gdb) where
#0  0x000055555557c6c9 in cargo_depgraph::graph::update_node ()
#1  0x000055555557c833 in cargo_depgraph::graph::update_node ()
#2  0x000055555557c833 in cargo_depgraph::graph::update_node ()
#3  0x000055555557c833 in cargo_depgraph::graph::update_node ()
#4  0x000055555557c833 in cargo_depgraph::graph::update_node ()
#5  0x000055555557c833 in cargo_depgraph::graph::update_node ()
#6  0x000055555557c833 in cargo_depgraph::graph::update_node ()
#7  0x000055555557c833 in cargo_depgraph::graph::update_node ()
#8  0x000055555557c833 in cargo_depgraph::graph::update_node ()
#9  0x000055555557c833 in cargo_depgraph::graph::update_node ()

Exclude flag still uses excluded packages to resolve features

Imported from sourcehut todos, originally reported by @vberger.

Tested on Smithay master (commit 25365ed69abbff56a9b188a37b9cd2469e2bc642).

Comparing:

  • running cargo depgraph --all-deps --exclude anvil --no-default-features on the bare repo
  • removing the [workspace] section in the Cargo.toml to make as if anvil did not exist, deleting Cargo.lock, and running cargo depgraph --all-deps --no-default-features

This first graph is very large and includes almost all dependencies, while the second is very small (as expected).

I suspect that even when anvil is excluded, it is still being used to resolved features, causing most of smithay's feature to be enabled even though the --no-default-features flag was passed.

Disambiguate multiple crates with the same name

At first, probably just adding a version to all crates of the same name, if there are multiple.

Later, crates could be disambiguated fully, adding even more info depending on what the crates (don't) differ in. E.g. a crate cr that is in the depgraph as a path dep once and a crates.io dep once, but both with the same version could be shown as cr [path = "../cr"] and cr [reg = "crates.io"] (leaving out the version).

Keep transitive deps that would look optional after pruning

Locally I wrote some code to generate the image below. This deduplicates transitive dependencies, but keeps those that 'go around' optional deps. I.e., the solid line between pa-web and pa-vis is nice because without it (the current behavior) it would seems as though a large part of the tree is optional, while in fact it's not.

Would you accept a PR for it? And in that case, what should the flag be named? I'm not sure myself. And should this be default?

depgraph

Readme guide missing a step

Hello,

The installation and first use guide is a bit hard to understand, I'm currently stuck as I don't know what "dot" is that the output of depgraph is being piped to, it's not a super easy thing to google either. It's not a recognized internal command on windows, so perhaps a brief explanation on what this is would help new users like myself?

Re-add --no-normal-deps

It was removed in 1157148 because it didn't actually work.

Note: a normal dependency of a build dependency should be shown with --build-deps --no-normal-deps. A dependency that is both a dev-dependency and a regular dependency, as well as its dependencies, should be shown with --dev-deps --no-normal-deps.

Add a way to customize the output

The default colors and styles might not be suitable for everything, and building in support for customization shouldn't be that hard.

As a workaround until this exists, one can already alter the emitted dot code before passing it to graphviz.

Add an option to change the roots

TBD:

  • Should it be possible to use a non-workspace crate as a root? (dev-dependencies couldn't be shown, but otherwise should not be a problem to implement)
  • What should the default in a workspace with a toplevel crate be: Have all workspace members as roots, or just the toplevel crate?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.