scikit-build-core icon indicating copy to clipboard operation
scikit-build-core copied to clipboard

How to make Makefiles the default generator?

Open chillenb opened this issue 3 months ago • 5 comments
trafficstars

Hi!

I am working on Python bindings for a library that uses Make. When Ninja is the generator, the Make-based sub-build does not respect CMAKE_BUILD_PARALLEL_LEVEL and takes a very long time. How can I set the default generator to be Makefiles in pyproject.toml? I'd rather keep this information in pyproject.toml rather than force users to type more stuff if they install from source.

chillenb avatar Jul 23 '25 21:07 chillenb

You can set CMAKE_GENERATOR environment variable or pass a -G flag to cmake.args. I doubt that Makefile will be faster. Not sure how you would check that it works with the appropriate parallelization other than trying it with values 1 and a very high one.

LecrisUT avatar Jul 23 '25 21:07 LecrisUT

I have set CMAKE_GENERATOR="Unix Makefiles" and it's indeed much faster. I was hoping that there was a way to set this with Ninja as a fallback, but I guess there isn't one. This would be nice for projects that use LTO, since Ninja still makes LTO use one thread with -flto=auto; you have to set -flto=n explicitly, at least with GCC.

chillenb avatar Jul 23 '25 22:07 chillenb

Oh, that's a useful nugget of information. Hmm, do you hard-code LTO in the CMakeLists or pass it as a variable. I wonder if this is a feature that should be exposed on CMake side. Could also be a bug in the handling of either one.

Afaik gcc will run LTO in serial mode if it died have make, but I am not sure how it detects it or if there has been improvements to not parallelize via make.

LecrisUT avatar Jul 23 '25 22:07 LecrisUT

CMake has INTERPROCEDURAL_OPTIMIZATION but I am not sure whether it solves the parallelization issue. Need to check the actual flags that it adds.

The cause of LTO serialization is the lack of GNU jobserver support in Ninja. Client support was added a few weeks ago but server support is still missing. I think this is a good reason to support Make and Ninja equally for now.

chillenb avatar Jul 23 '25 22:07 chillenb

I remember Henry mentioning that the Ninja used in the python wheels was the kitware fork so that it can have the jobserver support. But do the compilers or CMake know to pick up that the support there is present? You could try to add ninja to the build-system.requires and see if it makes a difference. If so better check with Henry for more context

LecrisUT avatar Jul 23 '25 22:07 LecrisUT