Skip to content

Commit ac7de03

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 778dd04 commit ac7de03

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
@@ -2255,7 +2255,7 @@ libainstall: all python-config
22552255
@if test "$(STATIC_LIBPYTHON)" = 1; then \
22562256
if test -d $(LIBRARY); then :; else \
22572257
if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
2258-
if test "$(SHLIB_SUFFIX)" = .dll; then \
2258+
if test "$(SHLIB_SUFFIX)" = .dll -o "$(SHLIB_SUFFIX)" = .pyd; then \
22592259
$(INSTALL_DATA) $(LDLIBRARY) $(DESTDIR)$(LIBPL) ; \
22602260
else \
22612261
$(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
@@ -3275,7 +3275,7 @@ if test -z "$SHLIB_SUFFIX"; then
32753275
*) SHLIB_SUFFIX=.so;;
32763276
esac
32773277
case $host_os in
3278-
mingw*) SHLIB_SUFFIX=.dll;;
3278+
mingw*) SHLIB_SUFFIX=.pyd;;
32793279
esac
32803280
fi
32813281
AC_MSG_RESULT($SHLIB_SUFFIX)
@@ -5934,6 +5934,68 @@ esac
59345934
# check for endianness
59355935
AC_C_BIGENDIAN
59365936

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

59686030
AC_SUBST(EXT_SUFFIX)
5969-
EXT_SUFFIX=.${SOABI}${SHLIB_SUFFIX}
6031+
VERSION_NO_DOTS=$(echo $LDVERSION | tr -d .)
6032+
if test -n "${PYD_PLATFORM_TAG}"; then
6033+
EXT_SUFFIX=".cp${VERSION_NO_DOTS}-${PYD_PLATFORM_TAG}${SHLIB_SUFFIX}"
6034+
else
6035+
EXT_SUFFIX=.${SOABI}${SHLIB_SUFFIX}
6036+
fi
59706037

59716038
AC_MSG_CHECKING(LDVERSION)
59726039
LDVERSION='$(VERSION)$(ABIFLAGS)'
@@ -6592,12 +6659,6 @@ case "$ac_cv_computed_gotos" in yes*)
65926659
AC_DEFINE(HAVE_COMPUTED_GOTOS, 1,
65936660
[Define if the C compiler supports computed gotos.])
65946661
esac
6595-
case $host_os in
6596-
mingw*)
6597-
dnl Synchronized with _PyImport_DynLoadFiletab (dynload_win.c)
6598-
dnl Do not use more then one dot on this platform !
6599-
EXT_SUFFIX=-$SOABI$SHLIB_SUFFIX;;
6600-
esac
66016662

66026663
case $ac_sys_system in
66036664
AIX*)

0 commit comments

Comments
 (0)