Skip to content
Latchkey

ninja Command: Fast Builds in CI

ninja executes build graphs quickly, focused on speed over hand-authoring.

Ninja is a minimal, very fast build system meant to be generated by tools like CMake or Meson rather than written by hand. In CI it executes the build.ninja graph with high parallelism, which is why CMake + Ninja is a common fast-build combination.

Common flags

  • -j N - run N jobs in parallel (defaults to detected core count)
  • -C DIR - change to DIR before building
  • -f FILE - use a build file other than build.ninja
  • -k N - keep going until N jobs fail (0 = unlimited)
  • -v - verbose: print full command lines
  • -t targets / -t clean - run a Ninja tool (list targets, clean)
  • -n - dry run; do not execute commands

Example in CI

Build a CMake-generated Ninja graph verbosely with bounded parallelism:

shell
ninja -C build -j$(nproc) -v

Common errors in CI

  • ninja: error: loading 'build.ninja': No such file or directory - not configured yet
  • ninja: error: unknown target 'X' - target not in the build graph
  • ninja: build stopped: subcommand failed - a compile/link step failed
  • ninja: error: manifest 'build.ninja' still dirty after 100 tries - regen loop

Key takeaways

  • Ninja files are generated (by CMake/Meson), not authored by hand.
  • "No such file" for build.ninja means you skipped the configure step.
  • Pair cmake -G Ninja with ninja for the fastest CI C/C++ builds.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →