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

Build platform ABI tag improvements #5437

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

wjakob
Copy link
Member

@wjakob wjakob commented Nov 10, 2024

With pybind11 and nanobind considering changes to the platform ABI tag, there is a nice opportunity to make them consistent with each other. This would make it potentially possible to later use that ABI tag to safely dispatch function calls between the two libraries.

This commit adapts the ABI tag as follows:

  • It removes PYBIND11_INTERNALS_KIND that was neither used nor documented.
  • It adapts the MSVC ABI tag to be less stringent (see PR Fix MSVC MT/MD incompatibility in PYBIND11_BUILD_ABI #4953)
  • It adapts the GCC ABI tag to be less stringent.
  • It adds a check for a Clang/libc++ ABI tag that wasn't present before

This commit adapts the ABI tag as follows:

- It removes ``PYBIND11_INTERNALS_KIND`` that was neither used nor documented.
- It adapts the MSVC ABI tag to be less stringent (see PR pybind#4953)
- It adapts the GCC ABI tag to be less stringent.
- It adds a check for a Clang/libc++ ABI tag that wasn't present before

I plan to make a consistent set of changes to nanobind so that both
libraries use interchangeable platform ABI tags.
Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

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

I didn't realize before that this is quite different from #4953.

I think it's best to handle Linux/macOS by itself in a separate PR, so that we can have a focussed discussion. — To add: Definitely, we should cover all platforms before we make a new pybind11 release.

# if (_MSC_VER) / 100 == 19
# define PYBIND11_BUILD_ABI NB_BUILD_LIB "_19"
# else
# define PYBIND11_BUILD_ABI NB_BUILD_LIB "_unknown"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel strongly that such a fallback will do more harm than good: people will mostly not know this is happening and will get surprised later, possibly after making releases already.

Generating an #error here means that we will know immediately that we need to update this code. It'll be under our control then to make this right.

Copy link
Member Author

Choose a reason for hiding this comment

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

As was discussed in PR #4953, MSVC has been ABI-compatible for ages. There is one huge ABI break looming some years in the future (MSVC "vNext") that will mark a transition towards the next island of stability.

Based on the information that is available, this looks to be a painful and disruptive break that will in any case require recompiling all Python packages for a new Windows base platform (i.e., similar to the different "manylinux" flavors). The check here is intended to catch that transition without making pybind11 completely unusable on the vNext version.

# define PYBIND11_BUILD_ABI NB_BUILD_LIB "_unknown"
# endif
#elif defined(_LIBCPP_ABI_VERSION)
# define PYBIND11_BUILD_ABI "_abi" NB_TOSTRING(_LIBCPP_ABI_VERSION)
Copy link
Collaborator

Choose a reason for hiding this comment

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

PYBIND11_TOSTRING?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right :D. Should I update the PR, or will you adapt the changes in #5439?

I noticed that you changed some of the specific strings so that the generated ABI IDs are now incompatible with nanobind. (e.g. _usecxx11 vs _legacy used here)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I didn't realize.

Could you maybe work on #5439 directly? (Maybe after git merge master; sorry I forgot to update the PR today.)

My hope was that we can work together on 5439 until everybody is happy with it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I forgot to add:

I believe initially it'll be best to #error for unknown situations, so that we're sure we're properly covering everything that we're testing with today. As a last step we can add in "unknown" fallbacks.

# define PYBIND11_BUILD_LIB ""
# endif
# if (_MSC_VER) / 100 == 19
# define PYBIND11_BUILD_ABI NB_BUILD_LIB "_19"
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is NB_BUILD_LIB defined?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was just a typo, fixed now.

@rwgk
Copy link
Collaborator

rwgk commented Nov 10, 2024

I just merged #5375: the code changed here now lives in include/pybind11/conduit/pybind11_platform_abi_id.h

@rwgk
Copy link
Collaborator

rwgk commented Nov 10, 2024

I had second but inconclusive thoughts about using #error vs #define "UNKNOWN":

We could have provisions for both:

  • Use #error in pybind11 GitHub Actions.
  • Use #define "UNKNOWN" otherwise.

This way we'd be forced to update the code here (pybind/pybind11), but not the rest of the world. This might be convenient in some situations, but I still believe will backfire in others. I'm not sure what'll be best overall.

@rwgk
Copy link
Collaborator

rwgk commented Nov 10, 2024

FYI I just created #5439. It may take me a few iterations there to get all GitHub Actions to pass. I'll then post an overview of the PYBIND11_PLATFORM_ABI_IDs seen in the logs. (I'll tag people when I reach a stage suitable for reviews.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants