Skip to content

Commit 68b7545

Browse files
lazkanaveen521kk
andcommitted
build: Add PYD_PLATFORM_TAG
Add PYD_PLATFORM_TAG to distinguish C extensions built with different MinGW toolchain configurations. The tag follows the format: mingw_<cpu_arch>_<c_runtime>_<toolchain> Where: - cpu_arch: x86_64, i686, aarch64, or armv7 - c_runtime: ucrt or msvcrt - toolchain: gnu or llvm This prevents loading extensions built with incompatible configurations. Co-authored-by: Naveen M K <naveen521kk@gmail.com>
1 parent 285c589 commit 68b7545

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

Makefile.pre.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ CONFINCLUDEPY= $(CONFINCLUDEDIR)/python$(LDVERSION)
166166
# Symbols used for using shared libraries
167167
SHLIB_SUFFIX= @SHLIB_SUFFIX@
168168
EXT_SUFFIX= @EXT_SUFFIX@
169+
PYD_PLATFORM_TAG = @PYD_PLATFORM_TAG@
169170
LDSHARED= @LDSHARED@ $(PY_LDFLAGS)
170171
BLDSHARED= @BLDSHARED@ $(PY_CORE_LDFLAGS)
171172
LDCXXSHARED= @LDCXXSHARED@ $(PY_LDFLAGS)

configure.ac

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6416,6 +6416,61 @@ esac
64166416
# check for endianness
64176417
AC_C_BIGENDIAN
64186418

6419+
AC_SUBST(PYD_PLATFORM_TAG)
6420+
# Special case of PYD_PLATFORM_TAG with python build with mingw.
6421+
# Python can with different cpu arch and c runtime as well as different
6422+
# toolchain. We follow this`mingw_<cpu_arch>_<c_runtime>_<toolchain>`
6423+
# convention for PYD_PLATFORM_TAG. Where:
6424+
# `cpu_arch` = `x86_64`, `aarch64` or `i686`
6425+
# `c_runtime` = `msvcrt` or `ucrt`
6426+
# `toolchain` = `gnu` or `llvm`
6427+
PYD_PLATFORM_TAG=""
6428+
case $host in
6429+
*-*-mingw*)
6430+
# check if we are linking to ucrt
6431+
AC_MSG_CHECKING(whether linking to ucrt)
6432+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
6433+
#include <stdio.h>
6434+
#ifndef _UCRT
6435+
#error no ucrt
6436+
#endif
6437+
int main(){ return 0; }
6438+
]])],[linking_to_ucrt=yes],[linking_to_ucrt=no])
6439+
AC_MSG_RESULT($linking_to_ucrt)
6440+
;;
6441+
esac
6442+
case $host_os in
6443+
mingw*)
6444+
AC_MSG_CHECKING(PYD_PLATFORM_TAG)
6445+
PYD_PLATFORM_TAG="mingw"
6446+
case $host in
6447+
i686-*-mingw*)
6448+
PYD_PLATFORM_TAG+="_i686"
6449+
;;
6450+
x86_64-*-mingw*)
6451+
PYD_PLATFORM_TAG+="_x86_64"
6452+
;;
6453+
aarch64-*-mingw*)
6454+
PYD_PLATFORM_TAG+="_aarch64"
6455+
;;
6456+
armv7-*-mingw*)
6457+
PYD_PLATFORM_TAG+="_armv7"
6458+
;;
6459+
esac
6460+
if test $linking_to_ucrt = no; then
6461+
PYD_PLATFORM_TAG+="_msvcrt"
6462+
else
6463+
PYD_PLATFORM_TAG+="_ucrt"
6464+
fi
6465+
if test -n "${cc_is_clang}"; then
6466+
# it is CLANG32
6467+
PYD_PLATFORM_TAG+="_llvm"
6468+
else
6469+
PYD_PLATFORM_TAG+="_gnu"
6470+
fi
6471+
AC_MSG_RESULT($PYD_PLATFORM_TAG)
6472+
esac
6473+
64196474
# ABI version string for Python extension modules. This appears between the
64206475
# periods in shared library file names, e.g. foo.<SOABI>.so. It is calculated
64216476
# from the following attributes which affect the ABI of this Python build (in

0 commit comments

Comments
 (0)