Skip to content

Commit 7a10c4a

Browse files
committed
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.
1 parent 037310e commit 7a10c4a

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

include/pybind11/detail/internals.h

+29-16
Original file line numberDiff line numberDiff line change
@@ -310,25 +310,38 @@ struct type_info {
310310
# endif
311311
#endif
312312

313-
/// On Linux/OSX, changes in __GXX_ABI_VERSION__ indicate ABI incompatibility.
314-
/// On MSVC, changes in _MSC_VER may indicate ABI incompatibility (#2898).
315-
#ifndef PYBIND11_BUILD_ABI
316-
# if defined(__GXX_ABI_VERSION)
317-
# define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_TOSTRING(__GXX_ABI_VERSION)
318-
# elif defined(_MSC_VER)
319-
# define PYBIND11_BUILD_ABI "_mscver" PYBIND11_TOSTRING(_MSC_VER)
320-
# else
321-
# define PYBIND11_BUILD_ABI ""
322-
# endif
323-
#endif
324-
325-
#ifndef PYBIND11_INTERNALS_KIND
326-
# define PYBIND11_INTERNALS_KIND ""
313+
// Catch other conditions that imply ABI incompatibility
314+
// - MSVC builds with different CRT versions
315+
// - An anticipated MSVC ABI break ("vNext")
316+
// - Builds using libc++ with unstable ABIs
317+
// - Builds using libstdc++ with the legacy (pre-C++11) ABI
318+
#if defined(_MSC_VER)
319+
# if defined(_MT) && defined(_DLL) // catches /MD or /MDd
320+
# define PYBIND11_BUILD_LIB "_md"
321+
# elif defined(_MT)
322+
# define PYBIND11_BUILD_LIB "_mt" // catches /MT or /MTd
323+
# else
324+
# define PYBIND11_BUILD_LIB ""
325+
# endif
326+
# if (_MSC_VER) / 100 == 19
327+
# define PYBIND11_BUILD_ABI NB_BUILD_LIB "_19"
328+
# else
329+
# define PYBIND11_BUILD_ABI NB_BUILD_LIB "_unknown"
330+
# endif
331+
#elif defined(_LIBCPP_ABI_VERSION)
332+
# define PYBIND11_BUILD_ABI "_abi" NB_TOSTRING(_LIBCPP_ABI_VERSION)
333+
#elif defined(__GLIBCXX__)
334+
# if _GLIBCXX_USE_CXX11_ABI
335+
# define PYBIND11_BUILD_ABI ""
336+
# else
337+
# define PYBIND11_BUILD_ABI "_legacy"
338+
# endif
339+
#else
340+
# define PYBIND11_BUILD_ABI ""
327341
#endif
328342

329343
#define PYBIND11_PLATFORM_ABI_ID \
330-
PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI \
331-
PYBIND11_BUILD_TYPE
344+
PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE
332345

333346
#define PYBIND11_INTERNALS_ID \
334347
"__pybind11_internals_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \

0 commit comments

Comments
 (0)