lukka / run-cmake

GitHub Action to build C++ applications with CMake (CMakePresets.json), Ninja and vcpkg on GitHub.
MIT License
181 stars 19 forks source link

Use parallelization #129

Open LecrisUT opened 10 months ago

LecrisUT commented 10 months ago

The action should set the following environment variables, especially when presets are used:

CMAKE_BUILD_PARALLEL_LEVEL: $(nproc)
CTEST_PARALLEL_LEVEL: $(nproc)

(effectively running cmake --build -j $(nproc) and ctest -j $(nproc))

These could be controlled by:

parallel: auto | none
build_parallel: ${parallel:-auto | none}
test_parallel: ${parallel:-auto | none}
lukka commented 10 months ago

@LecrisUT did you consider using jobs property in build and test presets of CMakePresets.json?

LecrisUT commented 10 months ago

Yes, but there is no macro expansion from cmake to get the $(nproc) dynamically. Also jobs value takes precedence so it should be safe to set is as a default

lukka commented 10 months ago

@LecrisUT The cmake invocation could be customized to satisfy any additional needs with the usage of the *AdditionalArgs and *CmdString inputs.

If those inputs are not enough, contribution to this project are welcome.

LecrisUT commented 10 months ago

Yes, but $(nproc) is a bit tricky because it is not a static variable: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#choosing-github-hosted-runners

But this should be a simple enough addition I can write it up

lukka commented 9 months ago

@LecrisUT I am trying to understand which problem we are trying to solve. When defining the value of CMAKE_BUILD_PARALLEL_LEVEL is going to be useful? I'd expect that delegating the choice to the current build tool is always the best choice because it should be able to utilize all the cpu available cycles, by default. For example, when using cmake and ninja, there is no need to specify any special additional value to ensure the build is as fast as possible on the system it is running on.

Could you show some workflows on GH which gives good use of such variable?

LecrisUT commented 9 months ago

For CMAKE_BUILD_PARALLEL_LEVEL it is more confusing than the test one. If we look at the -j documentation, there are a few caveats:

Setting CMAKE_BUILD_PARALLEL_LEVEL seems the most general way of solving this, even though it might not be as efficient as the automatic.

LecrisUT commented 9 months ago

About the preset options, these options are available, but: