GNOME Bugzilla – Bug 778784
Allow using Ninja with CMake modules
Last modified: 2018-01-06 22:17:17 UTC
Ninja is on average faster and more efficient than Make, especially on non-Unix platforms. CMake can generate Ninja build rules; we should allow modules to tell us they prefer using Ninja.
Created attachment 345988 [details] [review] Allow telling CMake modules to use Ninja Ninja is a replacement for Make; it's faster, simpler, and by default tries to take advantage of multiple cores and platform-specific efficient paths.
Created attachment 345989 [details] [review] apps-3.24: Use Ninja to build libgit2
Thanks for working on this. I think we should make this the default behavior for all modules and just not use the use-ninja flag at all. If there's some module that's really broken with ninja, which I guess is unlikely, then we can use a use-make flag instead.
The default is conservative because I wanted more testing to happen. In general, I think `use-ninja=yes` should be the default, and we should allow `use-ninja=no` as an escape hatch.
Created attachment 345991 [details] [review] cmake: Use Ninja by default Allow specifying 'use-ninja="no"' as an escape hatch.
Review of attachment 345988 [details] [review]: OK, squash the third patch into this one please.
Review of attachment 345989 [details] [review]: So this isn't needed anymore.
Review of attachment 345991 [details] [review]: Squash into the first patch please. This also avoids breaking current users of JHBuild, who won't have to upgrade immediately as the modulesets won't use use_ninja yet.
Created attachment 346013 [details] [review] Make CMake modules use Ninja instead of Make Ninja is a replacement for Make; it's faster, simpler, and by default tries to take advantage of multiple cores and platform-specific efficient paths. We use the Ninja generator by default, but we allow using the attribute 'use-ninja' as an escape hatch for the modules that prefer the Make generator.
Attachment 346013 [details] pushed as cb64cee - Make CMake modules use Ninja instead of Make
I'm trying to build WebKit, but I have only 4GB of RAM, and it swaps like hell, my computer is unusable during many hours. I want to pass -j1 to ninja, but it doesn't seem possible with jhbuild, there are no ninjaargs. With make, I can add this to my jhbuildrc: module_makeargs['WebKit'] = '-j1' I don't want to modify the moduleset, I prefer a solution where I can just configure my jhbuildrc. Do you have a solution?
(In reply to Sébastien Wilmet from comment #11) > I'm trying to build WebKit, but I have only 4GB of RAM, and it swaps like > hell, my computer is unusable during many hours. You really should not build WebKit with just 4GB of RAM, sorry. It's a lost cause. > I want to pass -j1 to ninja, but it doesn't seem possible with jhbuild, > there are no ninjaargs. A new issue to add a ninjaargs/module_ninjaargs configuration option would be okay. > I don't want to modify the moduleset, I prefer a solution where I can just > configure my jhbuildrc. Do you have a solution? Please, open a new issue. This issue was for adding the ability to build with CMake+Ninja modules.
I reopened this bug because the solution was incomplete IMHO. Anyway, there is already bug #782320 to add ninjaargs.
The provided patch did not work when Ninja is not installed with jhbuild version jhbuild-3.15.92+20171014~ed1297d Please consider to add "self.ensure_ninja_binary()" before testing self.use_ninja in all functions diff --git a/cmake.py b/cmake_mod.py index 71654a4..3bef0b3 100644 --- a/cmake.py +++ b/cmake_mod.py @@ -122,8 +122,8 @@ class CMakeModule(MakeModule, DownloadableModule): def do_clean(self, buildscript): buildscript.set_action(_('Cleaning'), self) builddir = self.get_builddir(buildscript) - self.ensure_ninja_binary() if self.use_ninja: + self.ensure_ninja_binary() buildscript.execute(self.ninja_binary + ' clean', cwd=builddir, extra_env=self.extra_env) else: self.make(buildscript, 'clean') @@ -133,8 +133,8 @@ class CMakeModule(MakeModule, DownloadableModule): def do_build(self, buildscript): buildscript.set_action(_('Building'), self) builddir = self.get_builddir(buildscript) - self.ensure_ninja_binary() if self.use_ninja: + self.ensure_ninja_binary() buildscript.execute(self.ninja_binary, cwd=builddir, extra_env=self.extra_env) else: self.make(buildscript) @@ -157,8 +157,8 @@ class CMakeModule(MakeModule, DownloadableModule): buildscript.set_action(_('Installing'), self) builddir = self.get_builddir(buildscript) destdir = self.prepare_installroot(buildscript) - self.ensure_ninja_binary() if self.use_ninja: + self.ensure_ninja_binary() extra_env = self.extra_env or {} extra_env['DESTDIR'] = destdir buildscript.execute(self.ninja_binary + ' install', cwd=builddir, extra_env=extra_env)
Corrected patch diff --git a/cmake.py b/cmake_mod.py index 3ea88b0..3bef0b3 100644 --- a/cmake.py +++ b/cmake_mod.py @@ -105,6 +105,7 @@ class CMakeModule(MakeModule, DownloadableModule): raise CommandError(_('%s not found') % 'cmake') baseargs = '-DCMAKE_INSTALL_PREFIX=%s -DCMAKE_INSTALL_LIBDIR=lib' % prefix cmakeargs = self.get_cmakeargs() + self.ensure_ninja_binary() if self.use_ninja: baseargs += ' -G Ninja' # CMake on Windows generates VS projects or NMake makefiles by default. @@ -121,8 +122,8 @@ class CMakeModule(MakeModule, DownloadableModule): def do_clean(self, buildscript): buildscript.set_action(_('Cleaning'), self) builddir = self.get_builddir(buildscript) - self.ensure_ninja_binary() if self.use_ninja: + self.ensure_ninja_binary() buildscript.execute(self.ninja_binary + ' clean', cwd=builddir, extra_env=self.extra_env) else: self.make(buildscript, 'clean') @@ -132,8 +133,8 @@ class CMakeModule(MakeModule, DownloadableModule): def do_build(self, buildscript): buildscript.set_action(_('Building'), self) builddir = self.get_builddir(buildscript) - self.ensure_ninja_binary() if self.use_ninja: + self.ensure_ninja_binary() buildscript.execute(self.ninja_binary, cwd=builddir, extra_env=self.extra_env) else: self.make(buildscript) @@ -156,8 +157,8 @@ class CMakeModule(MakeModule, DownloadableModule): buildscript.set_action(_('Installing'), self) builddir = self.get_builddir(buildscript) destdir = self.prepare_installroot(buildscript) - self.ensure_ninja_binary() if self.use_ninja: + self.ensure_ninja_binary() extra_env = self.extra_env or {} extra_env['DESTDIR'] = destdir buildscript.execute(self.ninja_binary + ' install', cwd=builddir, extra_env=extra_env)
Thanks! Could you please: - open a new bug, instead of re-purposing closed ones - describe your environment, i.e. how you ended up with jhbuild but without ninja - attach the patch instead of putting it into a comment - generate the patch using `git format-patch` or, better yet, through the `git-bz` tool
(In reply to Emmanuele Bassi (:ebassi) from comment #16) > Thanks! > > Could you please: > > - open a new bug, instead of re-purposing closed ones > - describe your environment, i.e. how you ended up with jhbuild but without > ninja Well it's not a build dependency, so the only way JHBuild can enforce the presence of ninja is to check for it as a sysdep. I've broken this in the past myself. Let's move discussion to bug #791476.
(In reply to Emmanuele Bassi (:ebassi) from comment #12) > You really should not build WebKit with just 4GB of RAM, sorry. It's a lost > cause. FYI, it worked well with -j1, run during the night (I don't contribute to WebKit, it was just to install a development version).
(In reply to Sébastien Wilmet from comment #18) > (In reply to Emmanuele Bassi (:ebassi) from comment #12) > > You really should not build WebKit with just 4GB of RAM, sorry. It's a lost > > cause. > > FYI, it worked well with -j1, run during the night (I don't contribute to > WebKit, it was just to install a development version). I think 2 GB should be enough, at least for release builds. Less than that would be pretty iffy.