From 7a10c4adb2269673d56ce4abc70afa0fa7e0edfb Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Mon, 11 Nov 2024 00:08:40 +0900 Subject: [PATCH 1/2] Build platform ABI tag improvements 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 #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. --- include/pybind11/detail/internals.h | 45 +++++++++++++++++++---------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index c960a86cb1..c579291442 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -310,25 +310,38 @@ struct type_info { # endif #endif -/// On Linux/OSX, changes in __GXX_ABI_VERSION__ indicate ABI incompatibility. -/// On MSVC, changes in _MSC_VER may indicate ABI incompatibility (#2898). -#ifndef PYBIND11_BUILD_ABI -# if defined(__GXX_ABI_VERSION) -# define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_TOSTRING(__GXX_ABI_VERSION) -# elif defined(_MSC_VER) -# define PYBIND11_BUILD_ABI "_mscver" PYBIND11_TOSTRING(_MSC_VER) -# else -# define PYBIND11_BUILD_ABI "" -# endif -#endif - -#ifndef PYBIND11_INTERNALS_KIND -# define PYBIND11_INTERNALS_KIND "" +// Catch other conditions that imply ABI incompatibility +// - MSVC builds with different CRT versions +// - An anticipated MSVC ABI break ("vNext") +// - Builds using libc++ with unstable ABIs +// - Builds using libstdc++ with the legacy (pre-C++11) ABI +#if defined(_MSC_VER) +# if defined(_MT) && defined(_DLL) // catches /MD or /MDd +# define PYBIND11_BUILD_LIB "_md" +# elif defined(_MT) +# define PYBIND11_BUILD_LIB "_mt" // catches /MT or /MTd +# else +# define PYBIND11_BUILD_LIB "" +# endif +# if (_MSC_VER) / 100 == 19 +# define PYBIND11_BUILD_ABI NB_BUILD_LIB "_19" +# else +# define PYBIND11_BUILD_ABI NB_BUILD_LIB "_unknown" +# endif +#elif defined(_LIBCPP_ABI_VERSION) +# define PYBIND11_BUILD_ABI "_abi" NB_TOSTRING(_LIBCPP_ABI_VERSION) +#elif defined(__GLIBCXX__) +# if _GLIBCXX_USE_CXX11_ABI +# define PYBIND11_BUILD_ABI "" +# else +# define PYBIND11_BUILD_ABI "_legacy" +# endif +#else +# define PYBIND11_BUILD_ABI "" #endif #define PYBIND11_PLATFORM_ABI_ID \ - PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI \ - PYBIND11_BUILD_TYPE + PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE #define PYBIND11_INTERNALS_ID \ "__pybind11_internals_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \ From 4b2675736faff0af05521a6b25a429187cc263cb Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Tue, 12 Nov 2024 13:59:36 +0900 Subject: [PATCH 2/2] Fix typos --- include/pybind11/detail/internals.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index c579291442..f11d1e5770 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -324,12 +324,12 @@ struct type_info { # define PYBIND11_BUILD_LIB "" # endif # if (_MSC_VER) / 100 == 19 -# define PYBIND11_BUILD_ABI NB_BUILD_LIB "_19" +# define PYBIND11_BUILD_ABI PYBIND11_BUILD_LIB "_19" # else -# define PYBIND11_BUILD_ABI NB_BUILD_LIB "_unknown" +# define PYBIND11_BUILD_ABI PYBIND11_BUILD_LIB "_unknown" # endif #elif defined(_LIBCPP_ABI_VERSION) -# define PYBIND11_BUILD_ABI "_abi" NB_TOSTRING(_LIBCPP_ABI_VERSION) +# define PYBIND11_BUILD_ABI "_abi" PYBIND11_TOSTRING(_LIBCPP_ABI_VERSION) #elif defined(__GLIBCXX__) # if _GLIBCXX_USE_CXX11_ABI # define PYBIND11_BUILD_ABI ""