You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何可视化Cabal项目的包依赖图?

Visualizing Cabal Project Dependencies (Beyond ghc-pkg dot)

Got it, I totally get the frustration with ghc-pkg dot—it’s great for inspecting the global/user GHC package database, but it doesn’t reflect the per-project dependency tree you’re actually working on with Cabal. Here are the most reliable tools and workflows to generate accurate dependency graphs tailored to your Cabal project:

1. Use cabal-plan (The Go-To Tool)

cabal-plan is purpose-built to parse Cabal’s build plans and generate dependency graphs that match your project’s exact constraints and resolved versions. It’s the gold standard for this use case.

  • First, install it (if you haven’t already):
    cabal install cabal-plan
    
  • Generate a DOT file of your project’s full dependency graph:
    cabal-plan dot > project-deps.dot
    
  • Convert the DOT file to a visual image (you’ll need Graphviz installed—most package managers offer it as graphviz):
    # Generate a PNG for quick viewing
    dot -Tpng project-deps.dot -o project-deps.png
    # Or an SVG for sharper, scalable output
    dot -Tsvg project-deps.dot -o project-deps.svg
    
  • Pro Tip: If the full graph is too cluttered, focus only on your project and its direct dependencies (prune transitive ones):
    cabal-plan dot --prune=none --focus=your-project-name > focused-deps.dot
    
    Replace your-project-name with the name of your Cabal package (from your .cabal file).

2. If You Use Stack: stack dot

If your Cabal project is managed with Stack, it has a built-in command to generate dependency graphs without extra tools:

  • Generate the DOT file, focusing only on project-specific dependencies:
    stack dot --project-only > project-deps.dot
    
  • Convert to a visual with Graphviz using the same commands as above.

3. Bonus: Nix Users Can Use nix-deps-graph

If you’re using Nix to manage your Cabal project’s dependencies, nix-deps-graph can generate a detailed graph that includes Nix-specific dependency details:

nix-build -A haskellPackages.your-project-name.dependencyGraph

This will output a DOT file you can render with Graphviz.

Quick Graphviz Tweaks for Better Readability

  • Use different layout engines to reduce clutter:
    # Neato for a force-directed, compact layout
    dot -Tsvg -Kneato project-deps.dot -o project-deps-neato.svg
    # FDP for another force-directed style that handles dense graphs well
    dot -Tsvg -Kfdp project-deps.dot -o project-deps-fdp.svg
    

内容的提问来源于stack exchange,提问作者Cigarette Smoking Man

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 20:47:42