Skip to content

Commit ec9c268

Browse files
isurufrwgkrobertmaynard
authored
Fix MSVC MT/MD incompatibility in PYBIND11_BUILD_ABI (#4953)
* Fix MSVC MT/MD incompatibility in PYBIND11_BUILD_ABI * Update comment about which PR * Use msvc major version * Use _MSC_VER/100 * Fix figuring out MD vs MT * Add some test runs * Skip one test * Fix preprocessor * simplify code * fix if * support only msvc 19 * Fold in changes from experimental PR #5411. Polish error messages. * Remove `&& defined(_DLL)` (TBD: is it needed? but what is correct?) * Fix MT vs MD * Add a couple comments, based on #4953 (comment) (posted by @isuruf). * Replace misleading comment: NVHPC is NOT outdated. * Update include/pybind11/detail/internals.h Co-authored-by: Robert Maynard <[email protected]> --------- Co-authored-by: Ralf W. Grosse-Kunstleve <[email protected]> Co-authored-by: Ralf W. Grosse-Kunstleve <[email protected]> Co-authored-by: Robert Maynard <[email protected]>
1 parent 037310e commit ec9c268

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

.github/workflows/ci.yml

+18
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ jobs:
6565
# Inject a couple Windows 2019 runs
6666
- runs-on: windows-2019
6767
python: '3.9'
68+
# Inject a few runs with different runtime libraries
69+
- runs-on: windows-2022
70+
python: '3.9'
71+
args: >
72+
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
73+
- runs-on: windows-2022
74+
python: '3.10'
75+
args: >
76+
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL
77+
# This needs a python built with MTd
78+
# - runs-on: windows-2022
79+
# python: '3.11'
80+
# args: >
81+
# -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug
82+
- runs-on: windows-2022
83+
python: '3.12'
84+
args: >
85+
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL
6886
# Extra ubuntu latest job
6987
- runs-on: ubuntu-latest
7088
python: '3.11'

include/pybind11/detail/internals.h

+20-6
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,29 @@ 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).
315313
#ifndef PYBIND11_BUILD_ABI
316-
# if defined(__GXX_ABI_VERSION)
314+
# if defined(__GXX_ABI_VERSION) // Linux/OSX.
317315
# 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)
316+
# elif defined(_MSC_VER) // See PR #4953.
317+
# if defined(_MT) && defined(_DLL) // Corresponding to CL command line options /MD or /MDd.
318+
# if (_MSC_VER) / 100 == 19
319+
# define PYBIND11_BUILD_ABI "_md_mscver19"
320+
# else
321+
# error "Unknown major version for MSC_VER: PLEASE REVISE THIS CODE."
322+
# endif
323+
# elif defined(_MT) // Corresponding to CL command line options /MT or /MTd.
324+
# define PYBIND11_BUILD_ABI "_mt_mscver" PYBIND11_TOSTRING(_MSC_VER)
325+
# else
326+
# if (_MSC_VER) / 100 == 19
327+
# define PYBIND11_BUILD_ABI "_none_mscver19"
328+
# else
329+
# error "Unknown major version for MSC_VER: PLEASE REVISE THIS CODE."
330+
# endif
331+
# endif
332+
# elif defined(__NVCOMPILER) // NVHPC (PGI-based).
333+
# define PYBIND11_BUILD_ABI "" // TODO: What should be here, to prevent UB?
320334
# else
321-
# define PYBIND11_BUILD_ABI ""
335+
# error "Unknown platform or compiler: PLEASE REVISE THIS CODE."
322336
# endif
323337
#endif
324338

0 commit comments

Comments
 (0)