ninja (build system)

{{Short description|Free build automation software}}

{{Infobox software

| name =Ninja

| developer = Evan Martin

| screenshot = Compiling dav1d screenshot.png

| caption = Ninja being used to compile dav1d, in conjunction with Meson configuration

| released = {{Start date and age|2012}}{{cite web|last1=Martin|first1=Evan|url=https://groups.google.com/forum/#!searchin/ninja-build/release%7Csort:date/ninja-build/wtfGmg0IoXQ/eH_tgL8eF8YJ|title=Google Groups: ninja-build|accessdate=18 June 2017}}

| latest release version = {{wikidata|property|preferred|references|edit|P348|P548=Q2804309}} | latest release date = {{Start date and age|{{wikidata|qualifier|preferred|single|P348|P548=Q2804309|P577}}|df=yes}}

| programming language = C++, Python

| operating system = Linux, macOS, Windows

| genre = Software development tools

| license = Apache License 2.0{{cite web |title=COPYING |url=https://github.com/ninja-build/ninja/blob/master/COPYING |website=Github |accessdate=5 September 2019}}

}}

Ninja is a build system developed by Evan Martin,{{cite web|url=https://www.theregister.com/2011/02/08/google_ninja_build_system_open_sourced/|title=Google man open sources Chrome build system}} 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.{{cite web |title=Ninja, a small build system with a focus on speed |url=https://ninja-build.org/ |website=ninja-build.org |access-date=21 January 2025}}

Build system

In essence, Ninja is meant to replace Make, which is slow when performing incremental (or no-op) builds.{{cite web|last1=Röthlisberger|first1=David|title=The Ninja build tool|url=https://lwn.net/Articles/706404/|website=LWN|accessdate=18 June 2017}} 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.{{cite web|title=Ninja|url=http://www.aosabook.org/en/posa/ninja.html|website=The Performance Of Open Source Applications|accessdate=18 June 2017}} It's also used to build Android (via Makefile translation by Kati),{{cite web|title=aosp mailing list|url=https://groups.google.com/forum/#!topic/android-platform/Hhl_4hfOONg/discussion}} and is used by most developers working on LLVM.{{cite web|title=LLVM documentation|url=https://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summary}}

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{{cite web|title=gn - Git at Google|url=https://gn.googlesource.com/gn/}} are popular build management software tools which support creating build files for Ninja.{{cite web|last1=Kitware|title=cmake Documentation|url=https://cmake.org/cmake/help/v3.8/generator/Ninja.html|accessdate=18 June 2017}}

Example

rule cc

command = gcc -c -o $out $in

description = CC $out

rule link

command = gcc -o $out $in

description = LINK $out

build source1.o: cc source1.c

build source2.o: cc source2.c

build myprogram: link source1.o source2.o

References

{{Reflist}}