Skip to content

Commit 3e41948

Browse files
rwgkcryospre-commit-ci[bot]
authored
PYBIND11_PLATFORM_ABI_ID Modernization Continued (platforms other than MSVC) (#5439)
* THIS IS JUST A START: First attempt to combine information from PR #4953 and PR #5437 * Include GXX_ABI and USE_CXX in the identifier Further constrain to GXX_ABI 1002 or greater and less than 2000, hopefully future proof by summarizing that as `1` along with CXX11 on or off. * style: pre-commit fixes * Use `gxx_abi_1xxx` and simplify the Clang string After discussions with Ralf Grosse-Kunstleve we think these would make good identifiers that are concise and clear. * Error if `_GLIBCXX_USE_CXX11_ABI` is not defined Within the `__GXX_ABI_VERSION` block this should always be defined, guard against unexpected defines and make the error obvious. * Change `usecxx11` to `use_cxx11_abi` for correspondence with `_GLIBCXX_USE_CXX11_ABI` (similarly to `gxx_abi` for `__GXX_ABI_VERSION`). * `PYBIND11_COMPILER_TYPE` overhaul, mainly: replace `_icc`, `_clang`, `_gcc` with `_system` * Add NVHPC (__PGI) to the list of compilers compatible with system compiler. See comment by @robertmaynard: #5439 (comment) * Fix oversight: remove __NVCOMPILER elif branch in PYBIND11_BUILD_ABI block. Also add comment pointing to this PR (#5439). * Revert "Fix oversight: remove __NVCOMPILER elif branch in PYBIND11_BUILD_ABI block." This reverts commit d412303. * Revert "Add NVHPC (__PGI) to the list of compilers compatible with system compiler." This reverts commit 9fc9515. * Define NVHPC PYBIND11_BUILD_ABI using __GNUC__, __GNUC_MINOR__, _GLIBCXX_USE_CXX11_ABI * Use _GLIBCXX_USE_CXX11_ABI to detect libstdc++, then assume that NVHPC is always in the 1xxx ABI family. * Enhance NVHPC comment and limited future proofing. * The `PYBIND11_STDLIB` is obsolete but kept around to maintain backward compatibility. * Move `PYBIND11_BUILD_TYPE` down in the file, so that the order of macro definitions is the same as in the list defining `PYBIND11_PLATFORM_ABI_ID` * Introduce `PYBIND11_COMPILER_TYPE_LEADING_UNDERSCORE`: This makes it possible to achieve these two goals: * Avoid the leading underscore in `PYBIND11_PLATFORM_ABI_ID` (see #5439 (comment)) * Maintain backward compatibility for use cases as reported under #5439 (comment) `PYBIND11_INTERNALS_KIND` is removed in this commit to ensure that `PYBIND11_COMPILER_TYPE` is the first element of the `PYBIND11_PLATFORM_ABI_ID`, so that `PYBIND11_COMPILER_TYPE_LEADING_UNDERSCORE` can meaningfully be used as a prefix for `PYBIND11_PLATFORM_ABI_ID` in pybind11/detail/internals.h. * Apply suggestion by @isuruf, with revised comments (code is as suggested). * Make determination of `PYBIND11_COMPILER_TYPE` `"macos"` or `"glibc"` more general. The main motivation is to resolve these "Manylinux on 🐍 3.13t • GIL" and "Pyodide wheel" failures: ``` /__w/pybind11/pybind11/include/pybind11/conduit/pybind11_platform_abi_id.h:35:10: error: #error "Unknown PYBIND11_COMPILER_TYPE: PLEASE REVISE THIS CODE." 35 | # error "Unknown PYBIND11_COMPILER_TYPE: PLEASE REVISE THIS CODE." | ^~~~~ ``` (All other CI jobs succeeded.) Further thought: Essentially, under Linux and macOS the `PYBIND11_COMPILER_TYPE` is only for informational purposes. ABI compatibility is determined by the libstdc++ or libc++ ABI version. * Add `PYBIND11_COMPILER_TYPE` `emscripten` * Add `PYBIND11_COMPILER_TYPE` `graalvm` * Revert "Add `PYBIND11_COMPILER_TYPE` `graalvm`" This reverts commit 75da5fb. * Revert "Add `PYBIND11_COMPILER_TYPE` `emscripten`" This reverts commit e34dc8b. * Revert "Make determination of `PYBIND11_COMPILER_TYPE` `"macos"` or `"glibc"` more general." This reverts commit 41daaa4. * Revert "Apply suggestion by @isuruf, with revised comments (code is as suggested)." This reverts commit ca9e699. * Remove `defined(__INTEL_COMPILER)` as suggested by @hpkfft under #5439 (comment) --------- Co-authored-by: Marcus D. Hanwell <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 741d86f commit 3e41948

File tree

2 files changed

+42
-43
lines changed

2 files changed

+42
-43
lines changed

include/pybind11/conduit/pybind11_platform_abi_id.h

+40-41
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,32 @@
1212
#define PYBIND11_PLATFORM_ABI_ID_STRINGIFY(x) #x
1313
#define PYBIND11_PLATFORM_ABI_ID_TOSTRING(x) PYBIND11_PLATFORM_ABI_ID_STRINGIFY(x)
1414

15-
// On MSVC, debug and release builds are not ABI-compatible!
16-
#if defined(_MSC_VER) && defined(_DEBUG)
17-
# define PYBIND11_BUILD_TYPE "_debug"
15+
#ifdef PYBIND11_COMPILER_TYPE
16+
// // To maintain backward compatibility (see PR #5439).
17+
# define PYBIND11_COMPILER_TYPE_LEADING_UNDERSCORE ""
1818
#else
19-
# define PYBIND11_BUILD_TYPE ""
20-
#endif
21-
22-
// Let's assume that different compilers are ABI-incompatible.
23-
// A user can manually set this string if they know their
24-
// compiler is compatible.
25-
#ifndef PYBIND11_COMPILER_TYPE
26-
# if defined(_MSC_VER)
27-
# define PYBIND11_COMPILER_TYPE "_msvc"
28-
# elif defined(__INTEL_COMPILER)
29-
# define PYBIND11_COMPILER_TYPE "_icc"
30-
# elif defined(__clang__)
31-
# define PYBIND11_COMPILER_TYPE "_clang"
32-
# elif defined(__PGI)
33-
# define PYBIND11_COMPILER_TYPE "_pgi"
34-
# elif defined(__MINGW32__)
35-
# define PYBIND11_COMPILER_TYPE "_mingw"
19+
# define PYBIND11_COMPILER_TYPE_LEADING_UNDERSCORE "_"
20+
# if defined(__MINGW32__)
21+
# define PYBIND11_COMPILER_TYPE "mingw"
3622
# elif defined(__CYGWIN__)
37-
# define PYBIND11_COMPILER_TYPE "_gcc_cygwin"
38-
# elif defined(__GNUC__)
39-
# define PYBIND11_COMPILER_TYPE "_gcc"
23+
# define PYBIND11_COMPILER_TYPE "gcc_cygwin"
24+
# elif defined(_MSC_VER)
25+
# define PYBIND11_COMPILER_TYPE "msvc"
26+
# elif defined(__clang__) || defined(__GNUC__)
27+
# define PYBIND11_COMPILER_TYPE "system" // Assumed compatible with system compiler.
4028
# else
41-
# define PYBIND11_COMPILER_TYPE "_unknown"
29+
# error "Unknown PYBIND11_COMPILER_TYPE: PLEASE REVISE THIS CODE."
4230
# endif
4331
#endif
4432

45-
// Also standard libs
33+
// PR #5439 made this macro obsolete. However, there are many manipulations of this macro in the
34+
// wild. Therefore, to maintain backward compatibility, it is kept around.
4635
#ifndef PYBIND11_STDLIB
47-
# if defined(_LIBCPP_VERSION)
48-
# define PYBIND11_STDLIB "_libcpp"
49-
# elif defined(__GLIBCXX__) || defined(__GLIBCPP__)
50-
# define PYBIND11_STDLIB "_libstdcpp"
51-
# else
52-
# define PYBIND11_STDLIB ""
53-
# endif
36+
# define PYBIND11_STDLIB ""
5437
#endif
5538

5639
#ifndef PYBIND11_BUILD_ABI
57-
# if defined(__GXX_ABI_VERSION) // Linux/OSX.
58-
# define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_PLATFORM_ABI_ID_TOSTRING(__GXX_ABI_VERSION)
59-
# elif defined(_MSC_VER) // See PR #4953.
40+
# if defined(_MSC_VER) // See PR #4953.
6041
# if defined(_MT) && defined(_DLL) // Corresponding to CL command line options /MD or /MDd.
6142
# if (_MSC_VER) / 100 == 19
6243
# define PYBIND11_BUILD_ABI "_md_mscver19"
@@ -72,17 +53,35 @@
7253
# error "Unknown major version for MSC_VER: PLEASE REVISE THIS CODE."
7354
# endif
7455
# endif
75-
# elif defined(__NVCOMPILER) // NVHPC (PGI-based).
76-
# define PYBIND11_BUILD_ABI "" // TODO: What should be here, to prevent UB?
56+
# elif defined(_LIBCPP_ABI_VERSION) // https://libcxx.llvm.org/DesignDocs/ABIVersioning.html
57+
# define PYBIND11_BUILD_ABI \
58+
"_libcpp_abi" PYBIND11_PLATFORM_ABI_ID_TOSTRING(_LIBCPP_ABI_VERSION)
59+
# elif defined(_GLIBCXX_USE_CXX11_ABI) // See PR #5439.
60+
# if defined(__NVCOMPILER)
61+
// // Assume that NVHPC is in the 1xxx ABI family.
62+
// // THIS ASSUMPTION IS NOT FUTURE PROOF but apparently the best we can do.
63+
// // Please let us know if there is a way to validate the assumption here.
64+
# elif !defined(__GXX_ABI_VERSION)
65+
# error \
66+
"Unknown platform or compiler (_GLIBCXX_USE_CXX11_ABI): PLEASE REVISE THIS CODE."
67+
# endif
68+
# if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION < 1002 || __GXX_ABI_VERSION >= 2000
69+
# error "Unknown platform or compiler (__GXX_ABI_VERSION): PLEASE REVISE THIS CODE."
70+
# endif
71+
# define PYBIND11_BUILD_ABI \
72+
"_libstdcpp_gxx_abi_1xxx_use_cxx11_abi_" PYBIND11_PLATFORM_ABI_ID_TOSTRING( \
73+
_GLIBCXX_USE_CXX11_ABI)
7774
# else
7875
# error "Unknown platform or compiler: PLEASE REVISE THIS CODE."
7976
# endif
8077
#endif
8178

82-
#ifndef PYBIND11_INTERNALS_KIND
83-
# define PYBIND11_INTERNALS_KIND ""
79+
// On MSVC, debug and release builds are not ABI-compatible!
80+
#if defined(_MSC_VER) && defined(_DEBUG)
81+
# define PYBIND11_BUILD_TYPE "_debug"
82+
#else
83+
# define PYBIND11_BUILD_TYPE ""
8484
#endif
8585

8686
#define PYBIND11_PLATFORM_ABI_ID \
87-
PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI \
88-
PYBIND11_BUILD_TYPE
87+
PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE

include/pybind11/detail/internals.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,11 @@ struct type_info {
272272

273273
#define PYBIND11_INTERNALS_ID \
274274
"__pybind11_internals_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
275-
PYBIND11_PLATFORM_ABI_ID "__"
275+
PYBIND11_COMPILER_TYPE_LEADING_UNDERSCORE PYBIND11_PLATFORM_ABI_ID "__"
276276

277277
#define PYBIND11_MODULE_LOCAL_ID \
278278
"__pybind11_module_local_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
279-
PYBIND11_PLATFORM_ABI_ID "__"
279+
PYBIND11_COMPILER_TYPE_LEADING_UNDERSCORE PYBIND11_PLATFORM_ABI_ID "__"
280280

281281
/// Each module locally stores a pointer to the `internals` data. The data
282282
/// itself is shared among modules with the same `PYBIND11_INTERNALS_ID`.

0 commit comments

Comments
 (0)