Skip to content
Latchkey

ninja -t: Inspect Targets and the Build Graph

ninja -t exposes inspection tools: list targets, dump the dependency graph, or print the commands for a target.

When you do not know what targets exist or why something rebuilds, ninja's -t subtools answer without running the build. They are read-only and safe to run in any CI step.

What it does

ninja -t targets lists buildable targets; -t commands prints the commands needed to build a target in order; -t graph emits a Graphviz dot graph of dependencies; -t deps shows the recorded header dependencies. These are diagnostics, not build actions.

Common usage

Terminal
ninja -C build -t targets         # list all targets
ninja -C build -t targets all     # list with rule names
ninja -C build -t commands my_app # commands to build my_app
ninja -C build -t graph | dot -Tpng -o graph.png

Options

SubtoolWhat it does
-t targetsList all targets ninja can build
-t commands <target>Print the build commands for a target
-t graph [<target>]Emit a Graphviz dependency graph
-t deps <target>Show recorded header dependencies
-t recompactCompact the .ninja_deps/.ninja_log files

In CI

Use -t targets in a debug step when "unknown target" surprises you across cmake/meson versions. -t commands reproduces the exact compiler invocation outside ninja, which is handy when bisecting a flag regression in a pipeline.

Common errors in CI

"unknown tool 'X'" means a misspelled subtool; run ninja -t list to see valid ones. An empty -t targets output means nothing is configured; check that cmake/meson actually generated build.ninja. -t graph producing no image means dot (graphviz) is not installed on the runner.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →