[php-src] PR #17445: Ninja support for MSVC
| From: | cmb69 | Date: | Sat, 11 Jan 2025 15:22:09 +0000 |
| Subject: | [php-src] PR #17445: Ninja support for MSVC | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-30354@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/17445
Author: cmb69
Contrary to many other make implementations, NMake does not support parallel builds. Instead, MS
enabled cl.exe for parallel compilation (
/MP), but that is not allowed for debug
builds, likely due to the [documented
limitation](https://learn.microsoft.com/en-us/cpp/build/reference/mp-build-with-multiple-processes):
> Most options are incompatible because if they were permitted, the concurrently executing
> compilers would write their output at the same time to the console or to a particular file. As a
> result, the output would intermix and be garbled.
This implies that debug builds are particularly slow (on my machine, unoptimized debug builds are
only minimally faster than fully optimized release builds; they are likely slower on more powerful
machines).
Now Visual Studio ships [Ninja](https://ninja-build.org/) as part of its CMake support, and Ninja
supports parallel builds. Thus I've hacked support for generating a build.ninja into our
Windows build tooling; just enough to be able to do a minimal build (configure --disable-all
--enable-cli --enable-debug), and was pleasantly surprised that this improved build time by a
factor of three (again, I expect even more impressive results with a more powerful machine). Release
builds are also slightly faster (about 10% percent).
Since Ninja supports header dependencies almost fully automatically, I've added support for
that as well, so it's no longer necessary to take care of that yourself (i.e. when making a
change to a header, nmake would do nothing; you need to touch relevant files, and for
changes to a Zend header, you usually need to nmake clean && nmake – terrible
UX). This works currently for German VS installations only (see comment below).
Another benefit of using Ninja instead of NMake is the console output during building. While our
NMake output is pretty verbose for debug builds, Ninja is terse, usually only showing one line of
progress, and only in case of a build failure showing the whole command that failed.
To round this up, there is still of lot of work to be done, but before doing that, I would like to
gauge interest in Ninja support – and maybe there are already other alternatives readily
available.
Maybe @nielsdos, @arnaud-lb and @bukka are interested in this.