# Ninja anyone?

**URL:** <https://alice-talk.web.cern.ch/t/ninja-anyone/66>\
**Category:** O²\
**Created:** [May 7, 2018, 1:08pm UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66 "2018-05-07T13:08:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![laphecet](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/laphecet/32/12_2.png) [@laphecet](https://alice-talk.web.cern.ch/u/laphecet)\
**Post date:** [May 7, 2018, 1:08pm UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/1 "2018-05-07T13:08:18Z")

</div>

Dear all,

I was wondering if there’s any strong reason why we’re using the make generator for cmake instead of e.g. ninja ?

I’ve been playing a bit with ninja lately and must say I like how it seems to be quite a bit quicker for recompilations (i.e. during regular dev cycle, after initial build, when you modify a file, re-compile, re-modify, re-compile, etc…).

Regards,

---

<div class="post-metadata">

**Author:** ![dberzano](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/dberzano/32/7_2.png) [@dberzano](https://alice-talk.web.cern.ch/u/dberzano)\
**Post date:** [May 7, 2018, 1:13pm UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/2 "2018-05-07T13:13:43Z")

</div>

We’ve been thinking about it. Are you volunteering for adding a ninja recipe and an O2 recipe building with ninja? 🙂

---

<div class="post-metadata">

**Author:** ![swenzel](https://alice-talk.web.cern.ch/letter_avatar_proxy/v4/letter/s/839c29/32.png) [@swenzel](https://alice-talk.web.cern.ch/u/swenzel)\
**Post date:** [May 7, 2018, 1:29pm UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/3 "2018-05-07T13:29:01Z")

</div>

Ninja is fantastic. The problem used to be that it cannot handle fortran. But this might no longer be the case and we should definitely investigate.

---

<div class="post-metadata">

**Author:** ![laphecet](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/laphecet/32/12_2.png) [@laphecet](https://alice-talk.web.cern.ch/u/laphecet)\
**Post date:** [May 7, 2018, 1:36pm UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/4 "2018-05-07T13:36:48Z")

</div>

can try to do that, yes.

---

<div class="post-metadata">

**Author:** ![bvonhall](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/bvonhall/32/8_2.png) [@bvonhall](https://alice-talk.web.cern.ch/u/bvonhall)\
**Post date:** [May 8, 2018, 6:04am UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/5 "2018-05-08T06:04:29Z")

</div>

I had tried it out with O2 and indeed it was nice and fast but the blocker was fortran.  
Go for it !

---

<div class="post-metadata">

**Author:** ![laphecet](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/laphecet/32/12_2.png) [@laphecet](https://alice-talk.web.cern.ch/u/laphecet)\
**Post date:** [May 8, 2018, 5:57pm UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/6 "2018-05-08T17:57:55Z")

</div>

Just to be sure, not counting our external dependencies (like Geant3 and some generators), we don’t use Fortran in O2, do we ?

---

<div class="post-metadata">

**Author:** ![swenzel](https://alice-talk.web.cern.ch/letter_avatar_proxy/v4/letter/s/839c29/32.png) [@swenzel](https://alice-talk.web.cern.ch/u/swenzel)\
**Post date:** [May 8, 2018, 7:17pm UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/7 "2018-05-08T19:17:06Z")

</div>

Yes. If it is just for O2 we should be safe.

---

<div class="post-metadata">

**Author:** ![dberzano](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/dberzano/32/7_2.png) [@dberzano](https://alice-talk.web.cern.ch/u/dberzano)\
**Post date:** [May 9, 2018, 9:00am UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/8 "2018-05-09T09:00:55Z")

</div>

OK so we will need:

- A proper [Ninja](https://ninja-build.org/) recipe, picking it from the system if possible, installing it if not (use `prefer_system` appropriately). We should properly check if the _right_ version is installed from the system there.
- A proper O2 recipe update (let’s start with it maybe) to use Ninja.

Concerning the last point, I think we can, maybe, **experiment with the [Common](https://github.com/AliceO2Group/Common) repository** for starters (there’s no Fortran code there and updates are not so frequent, making it an excellent testbed).

We will need to tell CMake to generate code using Ninja:

```bash
cmake $SOURCEDIR -G Ninja blahblah...

```

Then instead of `make` and `make install` we can directly use:

```bash
cmake --build . ${JOBS:+-- -j$JOBS} # "make"
cmake --build . --target install # "make install"

```

The above `cmake` statements are generic and work also with GNU Makefiles. I honestly don’t know if the installation procedure can be sped up by running it in parallel.

I am especially curious to see how our macOS installation time improves (if so) with Ninja!

Thanks for contributing!

---

<div class="post-metadata">

**Author:** ![laphecet](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/laphecet/32/12_2.png) [@laphecet](https://alice-talk.web.cern.ch/u/laphecet)\
**Post date:** [May 9, 2018, 9:06am UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/9 "2018-05-09T09:06:17Z")

</div>

An alidist PR is indeed in the works along those lines 😉  
Will try to post it today.

---

<div class="post-metadata">

**Author:** ![laphecet](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/laphecet/32/12_2.png) [@laphecet](https://alice-talk.web.cern.ch/u/laphecet)\
**Post date:** [May 9, 2018, 3:29pm UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/10 "2018-05-09T15:29:34Z")

</div>

PR done [https://github.com/alisw/alidist/pull/1136](https://github.com/alisw/alidist/pull/1136). Let’s see how it goes 😉

I did some timings while putting the PR in place, see  
[https://www.aphecetche.xyz/2018/05/09/ninja-vs-make/](https://www.aphecetche.xyz/2018/05/09/ninja-vs-make/)

To be really thorough one might imagine to check that all build artifacts (bin,libs) are actually the same for the make and ninja cases. Might actually do that next, as it might be useful if we want to evaluate more build systems at some point ?

---

<div class="post-metadata">

**Author:** ![eulisse](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/eulisse/32/19_2.png) [@eulisse](https://alice-talk.web.cern.ch/u/eulisse)\
**Post date:** [May 9, 2018, 8:03pm UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/11 "2018-05-09T20:03:05Z")

</div>

Do you understand why system time is so high in both cases?

---

<div class="post-metadata">

**Author:** ![laphecet](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/laphecet/32/12_2.png) [@laphecet](https://alice-talk.web.cern.ch/u/laphecet)\
**Post date:** [May 10, 2018, 8:41pm UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/12 "2018-05-10T20:41:19Z")

</div>

@eulisse : no

---

<div class="post-metadata">

**Author:** ![laphecet](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/laphecet/32/12_2.png) [@laphecet](https://alice-talk.web.cern.ch/u/laphecet)\
**Post date:** [May 11, 2018, 1:25pm UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/13 "2018-05-11T13:25:47Z")

</div>

Actually, finding out where the time is spent in our build might be of some interest.

Don’t know how to do it with ninja proper but apparently [shake](https://shakebuild.com/ninja) is able to use ninja files and seems to have a very nice build profiling output (report.html, that is query-able)

 ![04](https://alice-talk.web.cern.ch/uploads/default/original/1X/cc3f087642c3efb1f79abb15c18fd6be1304e2ae.png)

 ![45](https://alice-talk.web.cern.ch/uploads/default/original/1X/808a6cc02e94a0a72ec359b258b17c6e6ffe7b5c.png)

---

<div class="post-metadata">

**Author:** ![bvonhall](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/bvonhall/32/8_2.png) [@bvonhall](https://alice-talk.web.cern.ch/u/bvonhall)\
**Post date:** [May 14, 2018, 6:28am UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/14 "2018-05-14T06:28:45Z")

</div>

@costing could be interested in this.

---

<div class="post-metadata">

**Author:** ![dberzano](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/dberzano/32/7_2.png) [@dberzano](https://alice-talk.web.cern.ch/u/dberzano)\
**Post date:** [May 14, 2018, 7:38am UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/15 "2018-05-14T07:38:41Z")

</div>

Is it easy to integrate it into our builds? It would be nice to have such profiles produced automatically. We do that already with [coverage](https://codecov.io/gh/AliceO2Group/AliceO2/).

---

<div class="post-metadata">

**Author:** ![eulisse](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/eulisse/32/19_2.png) [@eulisse](https://alice-talk.web.cern.ch/u/eulisse)\
**Post date:** [May 14, 2018, 8:40am UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/16 "2018-05-14T08:40:42Z")

</div>

Can we get the report somewhere? Does it include compilation time only or also the overhead? I’ve the impression that we have something stupid (e.g. starting bash with interactive configuration) which dominates over compile time.

---

<div class="post-metadata">

**Author:** ![dberzano](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/dberzano/32/7_2.png) [@dberzano](https://alice-talk.web.cern.ch/u/dberzano)\
**Post date:** [May 14, 2018, 8:49am UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/17 "2018-05-14T08:49:12Z")

</div>

> [@eulisse](#):
>
> Can we get the report somewhere?

That was quite precisely my request, see above. I’d like to have a badge with it as you have done with Coverage.

On build time, well, I have made some research and opened a different topic earlier:

> [@Very slow CMake O2 installation on macOS](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68):
>
> At the moment, the installation process on macOS for O2 is painfully slow: a simple make install, or ninja install, issued in the build directory when nothing has changed in the source code takes around 6 minutes, whereas on my Linux node it takes three seconds. Apparently, the install target, when generated by CMake, cannot run in parallel (so that -j whatever has no effect), and quite some time is spent on relocating the binaries using install\_name\_tool -delete\_rpath ...: the net result is th…

---

<div class="post-metadata">

**Author:** ![laphecet](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/laphecet/32/12_2.png) [@laphecet](https://alice-talk.web.cern.ch/u/laphecet)\
**Post date:** [May 14, 2018, 9:00am UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/18 "2018-05-14T09:00:07Z")

</div>

@eulisse : the report I was referring to should now be available at  
[https://cernbox.cern.ch/index.php/s/TArbTGYGg5wqNbt](https://cernbox.cern.ch/index.php/s/TArbTGYGg5wqNbt)

As far as I can tell, I think the report covers everything. In the report, if you go to the “command plot” dropdown menu you’ll see 3 main area : c++ compilation (green), cd (red, which is not cd but dictionary / rootmap generation AFAIK), and “:” (light blue) which I’ve not figured out yet what it is ;-). Using the “command table” you get the numbers for each command (the number are the unparallel ones if I get it correctly, e.g. the total build is not 35minutes !)

| c++ | 459 × | 35m24s | 90.17% |
| --- | --- | --- | --- |
| cd | 47 × | 3m01s | 7.67% |
| : | 183 × | 36.61s | 1.55% |
| cmake | 1 × | 8.37s | 0.36% |
| cc | 1 × | 0.13s | 0.01% |

@dberzano : I’m no expert on shake itself (just installed it myself last week), but basically, once shake is installed (this requires the haskell platform…) and cmake has generated ninja files, it’s just a matter of doing `shake -jN --profile` (the -j is important as shake is using 1 core by default where ninja for instance is using everything available by default), so I’d say it should be easy to integrate, yes.

---

<div class="post-metadata">

**Author:** ![dberzano](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/dberzano/32/7_2.png) [@dberzano](https://alice-talk.web.cern.ch/u/dberzano)\
**Post date:** [May 14, 2018, 9:02am UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/19 "2018-05-14T09:02:36Z")

</div>

> [@laphecet](#):
>
> @dberzano : I’m no expert on shake itself (just installed it myself last week), but basically, once shake is installed (this requires the haskell platform…) and cmake has generated ninja files, it’s just a matter of doing shake -jN --profile (the -j is important as shake is using 1 core by default where ninja for instance is using everything available by default), so I’d say it should be easy to integrate, yes.

OK if you don’t mind I’ll try doing it for the next WP3 as a demonstrator!

---

<div class="post-metadata">

**Author:** ![laphecet](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/laphecet/32/12_2.png) [@laphecet](https://alice-talk.web.cern.ch/u/laphecet)\
**Post date:** [May 14, 2018, 9:03am UTC](https://alice-talk.web.cern.ch/t/ninja-anyone/66/20 "2018-05-14T09:03:11Z")

</div>

oh, and to be clear, what I timed was just the build (i.e. no install)

[Next page](https://alice-talk.web.cern.ch/t/ninja-anyone/66.md?page=2)
