How can I export a .dot file for dependency graph of Swift package target?

I'm using Swift package manager pretty extensively in my application - for all 3rd party packages, as well as ~150 local targets across ~9 local packages. My application target basically just imports the root of the swift package dependency graph and has the AppDelegate / SceneDelegate. I would like to export the resolved dependency graph including local and remote targets in a .dot graphviz format which I can visualize.

I know that this is possible because this PR was merged a while ago:

But I'm not sure how to invoke this either through Xcode or from the command line.
I'd love to be able to do something like:

swift build MyRootTarget --show-dependencies > graphviz

And see the graph of all the transitive dependencies of my root target.

2 Likes

Try this:

swift-package show-dependencies --format=dot

(Also try "swift-package show-dependencies --help" to see what formats are supported).

Hmm so that worked (though I had to run it as swift package show-dependencies --format dot) but it only shows me package dependencies and not product dependencies within those packages. Is it possible to build a product dependency graph?

Alternately, should I avoid putting multiple unrelated products in the same package? E.g. I have several module types like "Features" and "Services" which each have a Package.swift file with many (10+) targets / products like "SignInFeature", "UsersService" etc. What I'm trying to accomplish is mapping out the dependency graph for my package products. I could potentially move each product into its own Package.swift file, but that would be a lot of work.

1 Like
Terms of Service

Privacy Policy

Cookie Policy