scikit-build/cmake-python-distributions

cmake only runs make single-threaded (-j1)

arwedus opened this issue · 2 comments

Problem:

When I run the cmake pypi package version from catkin,
I get the following warning in the logs:

make: warning: jobserver unavailable: using -j1. Add '+' to parent make rule. which means nothing is built in parallel.

Also, CMake calls make with -j1, and the build is thus single-threaded.

Expected behavior:

cmake runs with job setting from catkin, which would result in a multi-threaded build (-j12).
This is what happens when using a CMake .deb package installation.

Analysis:

This only occurs when CMake is installed via pip. The problem with that is that in this case the entrypoint to CMake (/usr/local/bin/cmake) is a Python file which then subprocess.calls the actual CMake binary. However, since Python 3.2, file descriptors are not forwarded to child processes anymore by default and therefore the real CMake (and therefore also make) cannot access catkin's make jobserver and defaults to -j1. (see: https://docs.python.org/3/library/subprocess.html "Changed in version 3.2: The default for close_fds was changed from False to what is described above.". )

System:

  • Ubuntu 20.04 LTS
  • catkin_tools 0.8.5
  • Python 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]
  • cmake==3.23.3

This is a bug with how pip generates entry points, right? The entrypoint script should have a close_fds=False in it, and it doesn't? I don't know what I was thinking. The entry point script calls Python, not a binary.

Ahh, it is this one:

return subprocess.call([os.path.join(CMAKE_BIN_DIR, name)] + args)

Same issue in ninja. Which is really embarrassing since it's a fork of ninja specifically that adds jobserver support...