Skip to content

Commit 88f7241

Browse files
naveen521kklazka
authored andcommitted
Fix extension suffix for c-extensions on mingw
Python is compiled with various compilers which previously had same platform tags or extension suffix. This can be error prone while loading c-extensions, so now each compiler or runtime has a different extension suffix. Also, changed all extension to end with .pyd rather than .dll file. Fixes msys2/MINGW-packages#8843 Signed-off-by: Naveen M K <[email protected]>
1 parent 389e4cc commit 88f7241

File tree

3 files changed

+72
-17
lines changed

3 files changed

+72
-17
lines changed

Makefile.pre.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ CONFINCLUDEPY= $(CONFINCLUDEDIR)/python$(LDVERSION)
171171
# Symbols used for using shared libraries
172172
SHLIB_SUFFIX= @SHLIB_SUFFIX@
173173
EXT_SUFFIX= @EXT_SUFFIX@
174+
PYD_PLATFORM_TAG = @PYD_PLATFORM_TAG@
174175
LDSHARED= @LDSHARED@ $(PY_LDFLAGS)
175176
BLDSHARED= @BLDSHARED@ $(PY_CORE_LDFLAGS)
176177
LDCXXSHARED= @LDCXXSHARED@
@@ -1301,8 +1302,7 @@ Python/dynload_hpux.o: $(srcdir)/Python/dynload_hpux.c Makefile
13011302

13021303
Python/dynload_win.o: $(srcdir)/Python/dynload_win.c Makefile
13031304
$(CC) -c $(PY_CORE_CFLAGS) \
1304-
-DSHLIB_SUFFIX='"$(SHLIB_SUFFIX)"' \
1305-
-DEXT_SUFFIX='"$(EXT_SUFFIX)"' \
1305+
-DPYD_PLATFORM_TAG='"$(PYD_PLATFORM_TAG)"' \
13061306
-o $@ $(srcdir)/Python/dynload_win.c
13071307

13081308
Python/sysmodule.o: $(srcdir)/Python/sysmodule.c Makefile $(srcdir)/Include/pydtrace.h
@@ -2260,7 +2260,7 @@ libainstall: all python-config
22602260
@if test "$(STATIC_LIBPYTHON)" = 1; then \
22612261
if test -d $(LIBRARY); then :; else \
22622262
if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
2263-
if test "$(SHLIB_SUFFIX)" = .dll; then \
2263+
if test "$(SHLIB_SUFFIX)" = .dll -o "$(SHLIB_SUFFIX)" = .pyd; then \
22642264
$(INSTALL_DATA) $(LDLIBRARY) $(DESTDIR)$(LIBPL) ; \
22652265
else \
22662266
$(INSTALL_DATA) $(LIBRARY) $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \

Python/dynload_win.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@
2929
#define PYD_UNTAGGED_SUFFIX PYD_DEBUG_SUFFIX ".pyd"
3030

3131
const char *_PyImport_DynLoadFiletab[] = {
32-
#ifdef EXT_SUFFIX
33-
EXT_SUFFIX, /* include SOABI flags where is encoded debug */
34-
#endif
35-
#ifdef SHLIB_SUFFIX
36-
"-abi" PYTHON_ABI_STRING SHLIB_SUFFIX,
37-
#endif
3832
PYD_TAGGED_SUFFIX,
3933
PYD_UNTAGGED_SUFFIX,
4034
NULL

configure.ac

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3279,7 +3279,7 @@ if test -z "$SHLIB_SUFFIX"; then
32793279
*) SHLIB_SUFFIX=.so;;
32803280
esac
32813281
case $host_os in
3282-
mingw*) SHLIB_SUFFIX=.dll;;
3282+
mingw*) SHLIB_SUFFIX=.pyd;;
32833283
esac
32843284
fi
32853285
AC_MSG_RESULT($SHLIB_SUFFIX)
@@ -5938,6 +5938,68 @@ esac
59385938
# check for endianness
59395939
AC_C_BIGENDIAN
59405940

5941+
AC_SUBST(PYD_PLATFORM_TAG)
5942+
# Special case of PYD_PLATFORM_TAG with python build with mingw.
5943+
# Python can with compiled with clang or gcc and linked
5944+
# to msvcrt or ucrt. To avoid conflicts between them
5945+
# we are selecting the extension as based on the compiler
5946+
# and the runtime they link to
5947+
# gcc + x86_64 + msvcrt = cp{version number}-x86_64
5948+
# gcc + i686 + msvcrt = cp{version number}-i686
5949+
# gcc + x86_64 + ucrt = cp{version number}-x86_64-ucrt
5950+
# clang + x86_64 + ucrt = cp{version number}-x86_64-clang
5951+
# clang + i686 + ucrt = cp{version number}-i686-clang
5952+
5953+
PYD_PLATFORM_TAG=""
5954+
case $host in
5955+
*-*-mingw*)
5956+
# check if we are linking to ucrt
5957+
AC_MSG_CHECKING(whether linking to ucrt)
5958+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
5959+
#include <stdio.h>
5960+
#ifndef _UCRT
5961+
#error no ucrt
5962+
#endif
5963+
int main(){ return 0; }
5964+
]])],[linking_to_ucrt=yes],[linking_to_ucrt=no])
5965+
AC_MSG_RESULT($linking_to_ucrt)
5966+
;;
5967+
esac
5968+
case $host_os in
5969+
mingw*)
5970+
AC_MSG_CHECKING(PYD_PLATFORM_TAG)
5971+
case $host in
5972+
i686-*-mingw*)
5973+
if test -n "${cc_is_clang}"; then
5974+
# it is CLANG32
5975+
PYD_PLATFORM_TAG="mingw_i686_clang"
5976+
else
5977+
if test $linking_to_ucrt = no; then
5978+
PYD_PLATFORM_TAG="mingw_i686"
5979+
else
5980+
PYD_PLATFORM_TAG="mingw_i686_ucrt"
5981+
fi
5982+
fi
5983+
;;
5984+
x86_64-*-mingw*)
5985+
if test -n "${cc_is_clang}"; then
5986+
# it is CLANG64
5987+
PYD_PLATFORM_TAG="mingw_x86_64_clang"
5988+
else
5989+
if test $linking_to_ucrt = no; then
5990+
PYD_PLATFORM_TAG="mingw_x86_64"
5991+
else
5992+
PYD_PLATFORM_TAG="mingw_x86_64_ucrt"
5993+
fi
5994+
fi
5995+
;;
5996+
aarch64-*-mingw*)
5997+
PYD_PLATFORM_TAG+="mingw_aarch64"
5998+
;;
5999+
esac
6000+
AC_MSG_RESULT($PYD_PLATFORM_TAG)
6001+
esac
6002+
59416003
# ABI version string for Python extension modules. This appears between the
59426004
# periods in shared library file names, e.g. foo.<SOABI>.so. It is calculated
59436005
# from the following attributes which affect the ABI of this Python build (in
@@ -5970,7 +6032,12 @@ if test "$Py_DEBUG" = 'true' -a "$with_trace_refs" != "yes"; then
59706032
fi
59716033

59726034
AC_SUBST(EXT_SUFFIX)
5973-
EXT_SUFFIX=.${SOABI}${SHLIB_SUFFIX}
6035+
VERSION_NO_DOTS=$(echo $LDVERSION | tr -d .)
6036+
if test -n "${PYD_PLATFORM_TAG}"; then
6037+
EXT_SUFFIX=".cp${VERSION_NO_DOTS}-${PYD_PLATFORM_TAG}${SHLIB_SUFFIX}"
6038+
else
6039+
EXT_SUFFIX=.${SOABI}${SHLIB_SUFFIX}
6040+
fi
59746041

59756042
AC_MSG_CHECKING(LDVERSION)
59766043
LDVERSION='$(VERSION)$(ABIFLAGS)'
@@ -6596,12 +6663,6 @@ case "$ac_cv_computed_gotos" in yes*)
65966663
AC_DEFINE(HAVE_COMPUTED_GOTOS, 1,
65976664
[Define if the C compiler supports computed gotos.])
65986665
esac
6599-
case $host_os in
6600-
mingw*)
6601-
dnl Synchronized with _PyImport_DynLoadFiletab (dynload_win.c)
6602-
dnl Do not use more then one dot on this platform !
6603-
EXT_SUFFIX=-$SOABI$SHLIB_SUFFIX;;
6604-
esac
66056666

66066667
case $ac_sys_system in
66076668
AIX*)

0 commit comments

Comments
 (0)