-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cmake): upgrade maximum supported CMake version to 3.27 #4786
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but
- as I wrote before I don't know a lot about cmake, so definitely let's wait a bit for @henryiii to comment.
- and WOW, from a general software engineering perspective it seems very unfortunate that we have to change 10 files just to bump the maximum supported cmake version.
Definitely for a separate PR, but is there a way to improve the organization? Could we define the maximum supported version in one place for cmake, and in the documentation refer to that rather than duplicating it there as well?
Apologies for the delay. The single most important rule of CMake: upgrading CMake can never change your build. CMake 3.27 produces the exact same output as whatever was set as the maximum or minimum version of cmake. Otherwise, you'd not be able to update your system CMake without breaking builds. We can't "auto-switch" to FindPython because many packages use pybind11 then expect all the The bug here is that we were supposed to detect if a user had set a minimum or maximum to 3.27, but we are setting the maximum to 3.26 if we are used as a submodule (find_package CONFIG, which is how scikit-build-core recommends using pybind11, works correctly). To fix this, we need to detect this before our cmake requires call, or we could remove the requires call if this is a subpackage. |
@@ -18,7 +18,7 @@ information, see :doc:`/compiling`. | |||
|
|||
.. code-block:: cmake | |||
|
|||
cmake_minimum_required(VERSION 3.5...3.26) | |||
cmake_minimum_required(VERSION 3.5...3.27) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating all these is a good idea, though. :)
To be fair, most of the changes were in the documentation and the tests since I figured might as well get that updated, the only place where the change was really necessary was in the root |
Also, I see that one of the CI pipelines failed. However, I'm not sure how the error in that particular macOS build:
is related to my changes. Was that unexpected? |
Sorry I missed this question before: I don't think I've seen that failure, i.e. unexpected, but I also believe it's not related to the changes in this PR. Could you please git merge master, git push, to see if that resolves the issue? (please don't rebase or force push; that only makes it more tricky to follow the history; and when we merge this PR it will be squashed then)
I have a split mind: generally I think it's best to solve one problem at a time (i.e. have one PR for the bug fix, another for the better organization) ... but in this particular case, since you're replacing all 3.26 with 3.27 anyway, how much does it add to this PR to define and use |
I thought it would be pretty straightforward, but because the test There are definitely workarounds like having a separate file that defines the version and we parse that in each individual I have also merged |
Ok, the Mac / brew build failed again. Upon further inspection it looks like this is indeed caused by the changes here. Comparing with a previous successful pipeline, after the changes to prefer the modern Successful pipeline during CMake configure:
Failing pipeline during CMake configure:
After that, when it tries to go and run the Python tests via
it fails because it does not find the However, during the pip install step, there do not appear to be any unusual errors and it says that At this point, I'm not quite sure what to do. For some reason:
|
I'd try adding (in ci.yml)
to see if that helps to get us unstuck. If that's the only thing, maybe report a cmake bug. "brew install llvm" is a pretty unusual environment, it wouldn't be surprising if something subtle goes wrong. |
This seems to be the problem:
But why is that not a problem without this PR? — I'd feel paranoid enough at this point to open another PR with current master and a no-op trivial change. Does it actually still work? (I guess yes, but I'd do that low-effort sanity check first.) |
I thought so too at first, but you can see that same warning on the previous build that was successful, so I'm thinking it's something else. Looking at the logs, even after I changed the Python executable path for the
Furthermore, on this same latest CI run, an additional build failed. In this case, the processed failed during the
|
Ok, actually after doing some reading, the CMake variable is actually Unless I'm missing something, this means that this line in
actually has no effect, so it could be removed without any consequences. |
I just clicked the button to start the GHAs. Sorry it took me a while to get back here. There is a simple trick to get around that: include a trivial whitespace change in your commit that is detected and fixed by our pre-commit checks on push. When the pre-commit bot pushes the commit with the fix, GHA will run automatically. The only thing to remember is to git pull the whitespace fix before continuing with changes in your local repo. For example, this will do the trick: -cmake_minimum_required(VERSION 3.5)
+cmake_minimum_required(VERSION 3.5) |
@henryiii do you know if there is a story behind |
@polmes wrote:
@henryiii I'm really surprised by the breakdown of such a basic abstraction. Considering that this PR currently is essentially just replacing |
Regarding this failure: https://github.com/pybind/pybind11/actions/runs/5913710581/job/16048426600?pr=4786
I'm thinking let's just ignore it and hope it'll get fixed in the scipy project soon. |
For the classic FindPythonInterp, like the rest of CMake, all variables start with We have to be quite careful here to be completely backward compatible. Upgrading your CMake version should never break your build. That's why CMake 3.27 does not remove FindPythonInterp/FindPythonLibs unless you set your minimum or maximum version of CMake to 3.27, which acknowledges that you know about this change. We need to follow the same pattern and avoid changing anything for users who have not opted into the new system. There are some minor fixes that need to go in and documentation updates, so I'll work on some of those.
I'd rather stick with simple values - it's not hard at all to search & replace for them, and it keeps them looking like "normal" CMakeLists.txt's, something a user would write for themselves. The difficulty in this upgrade is that setting 3.27 causes a significant change (the removal of FindPythonLibs/FindPythonInterp) which we are having to adjust for. It's a bit tricker for us in testing because we do want to keep testing the old method too. |
Of course. And I think I see the current issue here where upgrading to the new CMake version could inadvertently switch your project to the new |
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
This reverts commit 33798ad.
Secondary changes: * pybind11 needs to be pinned to a version right before pybind/pybind11#4786 was merged, to avoid `ctest` `permission denied` errors (to be debugged separately). * `find_package(PythonLibs REQUIRED)` is removed. It is deprecated (https://github.com/pybind/pybind11/blob/master/docs/faq.rst) and evidently not needed. * More complete logging. PiperOrigin-RevId: 595435856
This PR broke https://github.com/pybind/pybind11_abseil testing. The latest version of pybind11_abseil is pinned to the pybind11 commit right before this PR. Test log (passed): https://github.com/pybind/pybind11_abseil/actions/runs/7400903531/job/20135518040 pybind/pybind11_abseil#14 pins pybind11_abseil to this PR (everything else is unchanged). Test log (failed): https://github.com/pybind/pybind11_abseil/actions/runs/7400974247/job/20135725540 This command appears to no longer work correctly:
This seems to be the critical diff (line breaks inserted manually to obtain an easily readable diff): 1: Test command:
/opt/hostedtoolcache/cmake/3.28.1/x64/cmake-3.28.1-linux-x86_64/bin/cmake
"-E"
"env"
"PYTHONPATH=$PYTHONPATH:/home/runner/work/pybind11_abseil/pybind11_abseil/tmp_build"
- "/home/runner/work/pybind11_abseil/pybind11_abseil/venv/bin/python"
"/home/runner/work/pybind11_abseil/pybind11_abseil/pybind11_abseil/tests/cpp_capsule_tools_testing_test.py" Does this ring any bells? I already tried setting |
Can look more in a hour or two. |
I am working on getting this fixed today. @henryiii do you have any updates on your end? |
To close the loop here: @david-crouse found this solution:
@henryiii is it intentional that only |
|
Ahh, you added this. No, the solution would be to set |
Following the suggestion here: pybind/pybind11#4786 (comment) Piggy-backed: Minor pre-commit auto-fix for top_level_CMakeLists.txt PiperOrigin-RevId: 597371220
Thanks, done: pybind/pybind11_abseil@52f2739#diff-67de6e1b7373ae9e30ad001b2f8b58e98aafd53263a12584c10d2913c6ecf63b The revised |
Description
This PR fixes the issue from #4785 by upgrading the maximum supported CMake version from 3.26 to 3.27. This allows the checks for the CMP0148 policy in
pybind11Common.cmake
to work as expected under CMake 3.27+, defaulting to the modernFindPython
CMake modules.This means that projects using CMake 3.27+ no longer need to set
to avoid warnings when using pybind11.
Additionally, projects that still rely on the "classic" CMake mode can now set
and pybind11 will then fall back to the deprecated
FindPythonInterp
andFindPythonLibs
modules logic.Suggested changelog entry: