|
12 | 12 | #define PYBIND11_PLATFORM_ABI_ID_STRINGIFY(x) #x |
13 | 13 | #define PYBIND11_PLATFORM_ABI_ID_TOSTRING(x) PYBIND11_PLATFORM_ABI_ID_STRINGIFY(x) |
14 | 14 |
|
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 "" |
18 | 18 | #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" |
36 | 22 | # 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. |
40 | 28 | # else |
41 | | -# define PYBIND11_COMPILER_TYPE "_unknown" |
| 29 | +# error "Unknown PYBIND11_COMPILER_TYPE: PLEASE REVISE THIS CODE." |
42 | 30 | # endif |
43 | 31 | #endif |
44 | 32 |
|
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. |
46 | 35 | #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 "" |
54 | 37 | #endif |
55 | 38 |
|
56 | 39 | #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. |
60 | 41 | # if defined(_MT) && defined(_DLL) // Corresponding to CL command line options /MD or /MDd. |
61 | 42 | # if (_MSC_VER) / 100 == 19 |
62 | 43 | # define PYBIND11_BUILD_ABI "_md_mscver19" |
|
72 | 53 | # error "Unknown major version for MSC_VER: PLEASE REVISE THIS CODE." |
73 | 54 | # endif |
74 | 55 | # 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) |
77 | 74 | # else |
78 | 75 | # error "Unknown platform or compiler: PLEASE REVISE THIS CODE." |
79 | 76 | # endif |
80 | 77 | #endif |
81 | 78 |
|
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 "" |
84 | 84 | #endif |
85 | 85 |
|
86 | 86 | #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 |
0 commit comments