Ninja

Last week I decided to evaluate “Ninja”.

What is it ?

It’s a build system developed by Chrome for Chrome. Evan Martin Developed it during his work.

He wanted to create a fast build system. It was a success :)

How to use it ?

Easy you need to create a file named Ninja.build which defines all dependancy as a Makefile.

But it’s not a problem because CMake is able to generate it for you.

So for KDE it’s not a problem as we use CMake to generate projects.

So now the command line:

“cmake -GNinja ../”

Too bad we can’t override default cmake generator. So I created a alias on my computer to avoid to write each time a big command line:

Add “alias cmninja=’cmake -GNinja’” in .alias

After that you call it you will have a “ninja.build” in build directory.

Now for launching the build it it’s very easy: write “ninja”

make <-> Ninja commands:

Ninja has same commands as Make.

make clean <-> ninja -t clean
make -j8   <-> ninja -j8
make install <-> ninja install
make -k <-> ninja -k[X] (it will stop after X failed)

Pro/Cons ?

Pro:

  • Faster as Make when we build from scratch
  • Less verbose as make
  • Very fast when we build and there is no files which changed (the time can be divided by 3 some time). So very fast when we rebuild all kde :)
  • Ninja will detect the amount of CPUs and use them all. (Not necessary to use ninja -j<X>)

Cons:

  • We don’t have color output.
  • We can’t build in subdirectory. For example if I build kdepim and I hack kmail, I can go to kmail subdirectory. I very bad for it.
  • qmake doesn’t generate ninja.build so we can’t use in qmake project.

Can I use in kdesrc-build?

Yes you can ! I use it.

Correction: We can use it in top-level.

This morning I fixed kf5-frameworks-build-include which forced build system.

So now you can add “custom-build-command ninja” in global settings of kdesrc-buildrc

cmake-options -GNinja -DCMAKE_BUILD_TYPE:STRING=debug -DKDE4_BUILD_TESTS=true

(just adds “-GNinja” to your current cmake-options)

So how I use it?

I use it for building all plasma5/kf5, it’s very fast to build. So I am happy.

For kdepim I still use make as I want to build in subdirectory.

More information:

You can have more information here: http://martine.github.io/ninja/manual.html

Trackback

8 comments untill now

  1. Hey! Nice article!

    I’ve been using Ninja for my cmake build directories for over a year now (maybe two?).

    I’m supper happy and wouldn’t go back.

  2. I like Ninja, especially because it is an alternative to Make. Many developers using Linux think, it is all about Make. With Ninja it is easier to teach them, that other build systems exist. That will create more portable code for OS X and Windows.

    Sadly, there are not many references for Ninja like an article on Wikipedia. Since the announcement no journalist covered Ninja. This makes it difficult to judge how important Ninja is. But many (CMake based) project use it nowadays.

  3. @Aleix: Indeed it’s a very good program. I didn’t test it before last week, but I will keep on it :)

    @uniq:”That will create more portable code for OS X and Windows.” why ? It’s cmake which allows it no ?
    It’s hard to find an article about it indeed. Each CMake based project can use it.

  4. Ninja does not support Fortan, which is still necessary for numerical software.
    If people have other build systems in mind, the code runs better in Xcode or Visual Studio, too.

  5. indeed fortran is not supported. And not sure that it will support in the future (see
    https://groups.google.com/forum/#!topic/ninja-build/b1-AF3pRJuE)

  6. Jussi Pakkanen @ 2015-02-26 09:52

    Note that Ninja will detect the amount of CPUs and use them all. Thus you almost never need to pass -j to it. Just do “ninja” instead, it will do the right thing automatically.

    Fortran support can be done in Ninja. It’s just CMake that does not know how to do it. As an example the Meson build system does Fortran with Ninja just fine. See under test cases/fortran here:

    https://github.com/jpakkane/meson

  7. @jussi: oh I forgot to inform that ninja detects number of processor indeed.
    Ok so fortran supports is a problem for cmake not ninja. Ok good to know.

  8. Laszlo Papp @ 2015-02-26 11:33

    When I switched to Ninja or so in 2012 for some of my pet projects, the only problem was that I could not convince my colleagues to use it on Windows for obvious reasons.

    The Windows part was not so mature back then. I do not use Windows anymore, but hopefully the situation is much improved now. :-)

    PS.: By the way, thanks for not using blogspot, etc, where someone without a similar account cannot comment!

Add your comment now