What is ninja?
Ninja is a tiny, high‑performance build system. It reads a plain‑text file called build.ninja that lists the steps (commands) needed to turn source files into final programs or libraries, and then it runs those steps as efficiently as possible.
Let's break it down
- build.ninja file - a list of rules (what command to run) and edges (which files depend on which).
- Rules - describe a command template, e.g., “compile C file with gcc”.
- Edges - connect inputs (source files) to outputs (object files) using a rule.
- The engine - Ninja looks at the dependency graph, figures out what’s out‑of‑date, and runs the needed commands in parallel.
Why does it matter?
Because building large codebases can be slow, Ninja’s focus on speed and minimal overhead makes compile‑times much shorter. Faster builds let developers test changes more often, which improves productivity and reduces the “feedback loop” time.
Where is it used?
- Google Chrome and Chromium projects
- Android Open Source Project (AOSP)
- Many C/C++ projects that generate Ninja files with CMake, Meson, or GN
- Rust’s Cargo can invoke Ninja when using certain build scripts
Good things about it
- Extremely fast, especially on multi‑core machines
- Simple file format that is easy for other tools to generate
- Works well with existing build generators (CMake, Meson, GN)
- Predictable, deterministic builds with minimal hidden magic
Not-so-good things
- The build.ninja file is not meant to be edited by hand; it’s hard to read for humans.
- Limited built‑in features (no built‑in testing, packaging, etc.) - you rely on other tools for those.
- Debugging failed builds can be tricky because Ninja only shows the command it ran, not higher‑level context.
- Less flexible than full‑featured systems like Make or Bazel when you need custom logic inside the build description.