Skip to content
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): support DEBUG_POSTFIX correctly #4761

Merged
merged 3 commits into from Sep 15, 2023

Conversation

lpapp-foundry
Copy link
Contributor

@lpapp-foundry lpapp-foundry commented Jul 25, 2023

Into suffix and debug postfix. Pybind11 is currently treating both as suffix, which is problematic when something else defines the DEBUG_POSTFIX because they will be concatenated.

pybind11_extension sets SUFFIX to _d.something and if DEBUG_POSTFIX is set to _d.

_d + _d.something = _d_d.something

The issue has been reported at:

#4699

Description

Suggested changelog entry:

* Support DEBUG_POSFIX correctly for debug builds

Into suffix and debug postfix. Pybind11 is currently treating both as
suffix, which is problematic when something else defines the
DEBUG_POSTFIX because they will be concatenated.

pybind11_extension sets SUFFIX to _d.something and if DEBUG_POSTFIX is
set to _d.

    _d + _d.something = _d_d.something

The issue has been reported at:

pybind#4699
@henryiii
Copy link
Collaborator

henryiii commented Aug 21, 2023

This only fixes the classic FindPythonInterp, which was removed in CMake 3.27 (sort-of). Is a similar fix needed for the modern FindPython? We try to keep both methods in sync. (Edit: I got this backwards, this is only fixing the new one).

@lpapp-foundry
Copy link
Contributor Author

lpapp-foundry commented Aug 21, 2023

This only fixes the classic FindPythonInterp, which was removed in CMake 3.27 (sort-of). Is a similar fix needed for the modern FindPython? We try to keep both methods in sync.

Thanks @henryiii, would you be able to elaborate on this?

As far as I can see, we are making a generic fix for the suffix and debug postfix independently from FindPythonInterp and FindPython? As far as I know, FindPythonInterp does not deal with suffix related things - it is a standalone find module that only invoked python for version information.

How is this related to FindPythonInterp and FindPython?

Apologies if I am missing something fundamental.


Update: do you mean fixes in this file? https://github.com/pybind/pybind11/blob/master/tools/FindPythonLibsNew.cmake?

E.g.: https://github.com/pybind/pybind11/blob/master/tools/FindPythonLibsNew.cmake#L175?

I have personally not hit issues in that file, but that is likely because I have not used it myself, so it would be challenging for me to fix that without being able to test it.

@henryiii
Copy link
Collaborator

henryiii commented Aug 21, 2023

Ahh, due to the classic style naming, I think I had it backwards, but in general tools/pybind11NewTools.cmake and tools/pybind11Tools.cmake should stay in sync. The "common to both" file is tools/pybind11Common.cmake. The old one uses tools/FindPythonLibsNew.cmake.

If you use FindPython before pybind11, or set PYBIND11_FINDPYTHON, you get the new one, otherwise you get the old one.

@henryiii
Copy link
Collaborator

Ahh, okay, slightly less worried about it since it's the old one. I can try to make the same change there in a couple of days (remind me if not).

@lpapp-foundry
Copy link
Contributor Author

lpapp-foundry commented Aug 21, 2023

Ahh, okay, slightly less worried about it since it's the old one. I can try to make the same change there in a couple of days (remind me if not).

Having had a quick look, to me, it looks like tools/pybind11Tools.cmake did not have this logic, so it looks like that we do not need to keep this in sync with regards to this patch. tools/pybind11Tools.cmake did not seem to have an internal fallback like that of tools/pybind11NewTools.cmake which is what this PR is trying to improve further. It looks like that tools/pybind11Tools.cmake just let the consumer to set this explicitly.

So, as far as I can see, at least, we are OK.

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
@henryiii henryiii changed the title cmake: split extension fix(cmake): support DEBUG_POSTFIX correctly Aug 21, 2023
@lpapp-foundry
Copy link
Contributor Author

@henryiii Thanks for the update. All looks great. Ready to go merge?

@lpapp-foundry
Copy link
Contributor Author

@henryiii You asked me to follow up in a couple of days. How is it going? Ready to merge?

@henryiii
Copy link
Collaborator

Trying to get at least one more set of eyes on it, just in case. :)

@lpapp-foundry
Copy link
Contributor Author

lpapp-foundry commented Aug 30, 2023

@friendlyanon already had an eye in the original ticket?

Would you like specifically another maintainer?

@henryiii
Copy link
Collaborator

Ideally I'd like another maintainer to okay it; according to our convention, since I didn't make the PR, my approval technically would be enough to merge it, but since I was involved in pushing to it, I'd like another maintainer just in case. :)

Thought someone else aware of the situation (and able to test it!) would be great. I don't have any way to test it, and our CI doesn't cover it, which is another reason a set of eyes looking at it that didn't write it would be nice.

@@ -172,13 +172,20 @@ _pybind11_get_if_undef(_PYTHON_VALUES 0 _PYTHON_VERSION_LIST)
_pybind11_get_if_undef(_PYTHON_VALUES 1 PYTHON_PREFIX)
_pybind11_get_if_undef(_PYTHON_VALUES 2 PYTHON_INCLUDE_DIR)
_pybind11_get_if_undef(_PYTHON_VALUES 3 PYTHON_SITE_PACKAGES)
_pybind11_get_if_undef(_PYTHON_VALUES 4 PYTHON_MODULE_EXTENSION)
_pybind11_get_if_undef(_PYTHON_VALUES 5 PYTHON_IS_DEBUG)
_pybind11_get_if_undef(_PYTHON_VALUES 6 PYTHON_SIZEOF_VOID_P)
_pybind11_get_if_undef(_PYTHON_VALUES 7 PYTHON_LIBRARY_SUFFIX)
_pybind11_get_if_undef(_PYTHON_VALUES 8 PYTHON_LIBDIR)
_pybind11_get_if_undef(_PYTHON_VALUES 9 PYTHON_MULTIARCH)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the banner comment at the top of the file is very much out of date considering all the variables that are set in this file. Not relevant here, just something to look out for.

_pybind11_get_if_undef(_PYTHON_VALUES 5 PYTHON_IS_DEBUG)
_pybind11_get_if_undef(_PYTHON_VALUES 6 PYTHON_SIZEOF_VOID_P)
_pybind11_get_if_undef(_PYTHON_VALUES 7 PYTHON_LIBRARY_SUFFIX)
_pybind11_get_if_undef(_PYTHON_VALUES 8 PYTHON_LIBDIR)
_pybind11_get_if_undef(_PYTHON_VALUES 9 PYTHON_MULTIARCH)

list(GET _PYTHON_VALUES 4 _PYTHON_MODULE_EXT_SUFFIX)
if(PYBIND11_PYTHONLIBS_OVERWRITE OR NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX)
get_filename_component(PYTHON_MODULE_DEBUG_POSTFIX "${_PYTHON_MODULE_EXT_SUFFIX}" NAME_WE)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is indeed more convenient doing the same thing than my original suggestion. Nice :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were you able to test this change? If so, I think it's safe to go in, though ideally another maintainer will review just for completeness.

Copy link
Collaborator

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 I don't write a ton of CMake.

@henryiii
Copy link
Collaborator

It is unit tested locally against the original change. And it's cleaner, simpler, and implemented in both required places, instead of just one.

I don't want a half-working change. I'd rather take it slow and get it right. I'm sure another maintainer will have a look shortly.

Pybind11 has been used by thousands of projects over many years. I think waiting a couple more days for a small fix is okay.

@henryiii henryiii merged commit 5891867 into pybind:master Sep 15, 2023
85 checks passed
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Sep 15, 2023
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants