Ninja (build system)

Last updated
Ninja
Developer(s) Evan Martin
Initial release2012;13 years ago (2012) [1]
Stable release
1.13.1 [2]   OOjs UI icon edit-ltr-progressive.svg / 11 July 2025;46 days ago (11 July 2025)
Repository
Written in C++, Python
Operating system Linux, macOS, Windows
Type Software development tools
License Apache License 2.0 [3]
Website ninja-build.org   OOjs UI icon edit-ltr-progressive.svg

Ninja is a build system developed by Evan Martin, [4] a Google employee. Ninja has a focus on speed and it differs from other build systems in two major respects: it is designed to have its input files generated by a higher-level build system, and it is designed to run builds as fast as possible. [5]

Contents

Build system

In essence, Ninja is meant to replace Make, which is slow when performing incremental (or no-op) builds. [6] This can considerably slow down developers working on large projects, such as Google Chrome, which compiles 40,000 input files into a single executable. In fact, Google Chrome is a main user and motivation for Ninja. [7] It's also used to build Android (via Makefile translation by Kati), [8] and is used by most developers working on LLVM. [9]

In contrast to Make, Ninja lacks features such as string manipulation, as Ninja build files are not meant to be written by hand. Instead, a "build generator" should be used to generate Ninja build files. Gyp, CMake, Meson, and gn [10] are popular build management tools that support creating build files for Ninja. [11]

Example

Below is an example of a Ninja build file that compiles two C source files (source1.c and source2.c) into object files and then links them into an executable called myprogram. It defines two rules: one for compiling (cc) and one for linking (link):

rulecccommand=gcc-c-o$out$indescription=CC$outrulelinkcommand=gcc-o$out$indescription=LINK$outbuild source1.o:ccsource1.cbuild source2.o:ccsource2.cbuild myprogram:linksource1.osource2.o

References

  1. Martin, Evan. "Google Groups: ninja-build" . Retrieved 18 June 2017.
  2. "Release v1.13.1". 11 July 2025. Retrieved 11 July 2025.
  3. "COPYING". Github. Retrieved 5 September 2019.
  4. "Google man open sources Chrome build system".
  5. "Ninja, a small build system with a focus on speed". ninja-build.org. Retrieved 21 January 2025.
  6. Röthlisberger, David. "The Ninja build tool". LWN. Retrieved 18 June 2017.
  7. "Ninja". The Performance Of Open Source Applications. Retrieved 18 June 2017.
  8. "aosp mailing list".
  9. "LLVM documentation".
  10. "gn - Git at Google".
  11. Kitware. "cmake Documentation" . Retrieved 18 June 2017.