TExcelTAD

The Dependency Graph

Every conan install starts by building a dependency graph: your conanfile at the root, its requirements, their requirements, and so on, with one node per package. Conan resolves the graph first (which recipes, which versions), then decides the binary for every node. When something goes wrong, the graph is the first thing to look at, and conan graph info shows it without installing anything.

conan graph info

Run on a project, conan graph info prints a lot: every field of every node. --filter keeps only the fields you ask for:

bash · try it yourself
mkdir -p app && cd app
cat > conanfile.txt <<'TXT'
[requires]
spdlog/1.17.0

[test_requires]
catch2/3.16.0
TXT
conan graph info . --filter=label --filter=package_id --filter=context 2>&1 | sed -n '/Basic graph information/,$p'
-------- Basic graph information --------
conanfile:
  ref: conanfile
  package_id: None
  label: conanfile.txt
  context: host
spdlog/1.17.0#bcbaaf7147bda6ad24ffbd1ac3d7142c:
  ref: spdlog/1.17.0#bcbaaf7147bda6ad24ffbd1ac3d7142c
  package_id: 68cf2b888a31d527b3476ac5bf6707b2db1ccd2d
  label: spdlog/1.17.0
  context: host
fmt/12.1.0#6baf0fb8351783472b94ee6e36232391:
  ref: fmt/12.1.0#6baf0fb8351783472b94ee6e36232391
  package_id: e02956bd268869d4519cb2b90dc7b4e51911a5d0
  label: fmt/12.1.0
  context: host
catch2/3.16.0#95f400ca2fba9f0c5ce5aea6e6fe0055:
  ref: catch2/3.16.0#95f400ca2fba9f0c5ce5aea6e6fe0055
  package_id: 0f8cc6d42d139bedbf85b2468778df7dbd2bd497
  label: catch2/3.16.0
  context: host
cmake/4.4.4#fec9c7048fae91e03c31e59977cd9c12:
  ref: cmake/4.4.4#fec9c7048fae91e03c31e59977cd9c12
  package_id: 63fead0844576fc02943e16909f08fcdddd6f44b
  label: cmake/4.4.4
  context: build

Five nodes, not three: catch2 declares cmake/4.4.4 as a tool requirement (it needs CMake to build itself), so it appears in the build context. Everything your code links is in the host context. The cmake node has a package ID too, but because Catch2's binary already exists, Conan skips that tool entirely (Skipped build binaries in the install output).

Drawing it

--format=dot writes Graphviz, which you can turn into an image with dot -Tsvg; --format=html writes an interactive page; --format=json is for scripts:

bash · try it yourself
mkdir -p app && cd app
printf '[requires]\nspdlog/1.17.0\n\n[test_requires]\ncatch2/3.16.0\n' > conanfile.txt
conan graph info . --format=dot 2>/dev/null
digraph {
        "conanfile.txt" -> "spdlog/1.17.0"
        "conanfile.txt" -> "catch2/3.16.0"
        "spdlog/1.17.0" -> "fmt/12.1.0"
        "catch2/3.16.0" -> "cmake/4.4.4"
}
bash
conan graph info . --format=html > graph.html   # open it in a browser

Edges carry traits

An edge is more than "A needs B". Each requirement has traits that say how B is used, and Conan computes them for transitive edges too. The JSON output shows them:

bash · try it yourself
mkdir -p app && cd app
printf '[requires]\nspdlog/1.17.0\n\n[test_requires]\ncatch2/3.16.0\n' > conanfile.txt
conan graph info . --format=json 2>/dev/null > graph.json
python3 - <<'PY'
import json
nodes = json.load(open("graph.json"))["graph"]["nodes"]
print(f"{'from':<14} {'to':<14} {'direct':<7} {'headers':<8} {'libs':<6} {'build':<6} test")
for node in nodes.values():
    src = node["label"]
    for dep in node["dependencies"].values():
        print(f"{src:<14} {dep['ref']:<14} {str(dep['direct']):<7} {str(dep['headers']):<8} "
              f"{str(dep['libs']):<6} {str(dep['build']):<6} {dep['test']}")
PY
from           to             direct  headers  libs   build  test
conanfile.txt  spdlog/1.17.0  True    True     True   False  False
conanfile.txt  fmt/12.1.0     False   True     True   False  False
conanfile.txt  catch2/3.16.0  True    True     True   False  True
spdlog/1.17.0  fmt/12.1.0     True    True     True   False  False
catch2/3.16.0  cmake/4.4.4    True    False    False  True   False
  • fmt is not direct for the app but still has headers and libs: spdlog's headers include fmt's, so the app needs fmt's include path and library too. Conan propagates them automatically.
  • catch2 is a test requirement (test=True); it would not propagate to anyone consuming this project.
  • cmake is a build requirement (build=True, no headers, no libs): it runs, it isn't linked.

In a recipe you can set traits explicitly, for example self.requires("zlib/1.3.1", transitive_headers=True) when your public headers include zlib's, or visible=False for a private implementation detail.

Build order

When binaries are missing, Conan must build them in dependency order: fmt before spdlog, because spdlog's build needs fmt's package. CI systems that build a big graph in parallel ask Conan for that order with conan graph build-order. The idea is a topological sort by levels, where each level can build in parallel:

python · try it yourself
graph = {
    "app":     ["spdlog", "catch2", "zlib", "openssl"],
    "spdlog":  ["fmt"],
    "fmt":     [],
    "catch2":  ["cmake"],
    "cmake":   [],
    "openssl": ["zlib"],
    "zlib":    [],
}

def build_levels(graph, root):
    done, levels = set(), []
    todo = {n for n in graph if n != root}
    while todo:
        ready = sorted(n for n in todo if all(d in done for d in graph[n]))
        if not ready:
            raise ValueError(f"cycle among {sorted(todo)}")
        levels.append(ready)
        done.update(ready)
        todo -= set(ready)
    return levels

for i, level in enumerate(build_levels(graph, "app"), 1):
    print(f"level {i}: {', '.join(level)}")
level 1: cmake, fmt, zlib
level 2: catch2, openssl, spdlog

Real build orders also group by package ID (one recipe can need several binaries) and skip nodes whose binaries exist. conan graph build-order . --build=missing --order-by=recipe --format=json gives you the same levels for a real project, ready to fan out to CI jobs.

Test yourself

Why does the graph contain cmake/4.4.4 when the app never asked for it?

  1. Conan always adds CMake
  2. Catch2's recipe declares it as a tool requirement, so it's a build-context node
  3. spdlog needs it to link
  4. It's in the default profile

fmt is not a direct dependency of the app. Why does the app still get fmt's include path and library?

  1. Because of a bug
  2. spdlog's requirement on fmt propagates headers and libs to spdlog's consumers
  3. CMake searches /usr/include
  4. The app must list fmt explicitly

In the build-order model, why are fmt, cmake and zlib on level 1?

  1. They are alphabetically first
  2. They have no dependencies, so nothing has to be built before them
  3. They are the largest
  4. They are header-only