Ninja と GN について

2 min read読了の目安(約2500字

Fuchsia OS(本家ウィキペディア) で使われているビルドシステム Ninja と GN についての簡単な紹介です。

要約

  • Ninja
    make 相等。ビルドが早い。
    Makefile の代わりに XXX.ninja ファイルを使う。

  • GN
    CMake 相等。XXX.ninja ファイルを生成する。
    GN は Generate Ninja の略。

本家リンク

  • Ninja
    Ninja is a small build system with a focus on speed.

  • GN
    GN is a meta-build system that generates build files for Ninja.

Ninja

Fuchsia OS では、make の代わりに Ninja を使用しています。
以下、Ninja を使用する理由。

Ninja is very simple compared to something like GNU make. It just compares
times and runs commands and its input files are written by machines, not
humans. However, it builds in some useful things that we bend over > backward
to accomplish in make:

  • Rebuild each file when the command line changes. Command lines will only
    really change when GN runs again. But after that, Ninja is smart about
    incremental builds re-doing commands for files that have changed and not
    re-running commands that haven't changed.
  • Handle compiler-generated dependency files. Ninja knows about the makefile
    subset that compilers emit in .d files and consumes them directly when
    directed to by GN.
  • Run with -j$(getconf _NPROCESSORS_ONLN) by default. You can pass -j1
    to serialize or -j1024 when using Goma, but out of the box it does the
    parallelism you usually want.
  • Prevent interleaved stdout/stderr output from parallel jobs. Ninja
    buffers the output so that error messages don't get garbled by spew from
    multiple processes.
  • Support terse/verbose command output. By default, Ninja emits short
    Kbuild-style messages for each command it runs, in a wordy-progress-meter
    style. The -v switch is like V=1 in Kbuild, to show each actual command.

Introduction to GN  |  Fuchsia

GN

Fuchsia OS では、XXX.ninja ファイル生成のために GN を使用しています。

GN was developed as part of the Chromium project to replace older build
systems. Fuchsia inherited it from them, and it is now used across the tree as
the primary build system.

Introduction to GN  |  Fuchsia