From 47d4f92391b89394e4152c4290dc09a76bc16756 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Tue, 22 Aug 2023 20:49:45 +0200 Subject: [PATCH] python: Update (libpython3.dll) see https://github.com/msys2-contrib/cpython-mingw/pull/148 --- ...-include-lib-dirs-from-CFLAGS-LDFLAG.patch | 30 +++++ ...143-Build-and-install-libpython3.dll.patch | 108 ++++++++++++++++++ mingw-w64-python/PKGBUILD | 14 ++- 3 files changed, 148 insertions(+), 4 deletions(-) create mode 100644 mingw-w64-python/0142-Allow-picking-up-include-lib-dirs-from-CFLAGS-LDFLAG.patch create mode 100644 mingw-w64-python/0143-Build-and-install-libpython3.dll.patch diff --git a/mingw-w64-python/0142-Allow-picking-up-include-lib-dirs-from-CFLAGS-LDFLAG.patch b/mingw-w64-python/0142-Allow-picking-up-include-lib-dirs-from-CFLAGS-LDFLAG.patch new file mode 100644 index 0000000000000..fbd0db3fdc6aa --- /dev/null +++ b/mingw-w64-python/0142-Allow-picking-up-include-lib-dirs-from-CFLAGS-LDFLAG.patch @@ -0,0 +1,30 @@ +From 95b1546da60ce10fc038f51790bf799d3780d37a Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Martin=20Storsj=C3=B6?= +Date: Wed, 16 Aug 2023 11:35:08 +0300 +Subject: [PATCH 142/N] Allow picking up include/lib dirs from CFLAGS/LDFLAGS + for Windows targets +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +In cpython-mingw-3.10, this was part of a patch named "allow static +tcltk". + +Co-authored-by: Алексей +--- + setup.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/setup.py b/setup.py +index 99ef3ed..e4f15d8 100644 +--- a/setup.py ++++ b/setup.py +@@ -924,7 +924,7 @@ class PyBuildExt(build_ext): + if HOST_PLATFORM == 'hp-ux11': + self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32'] + +- if MACOS: ++ if MACOS or MS_WINDOWS: + # This should work on any unixy platform ;-) + # If the user has bothered specifying additional -I and -L flags + # in OPT and LDFLAGS we might as well use them here. diff --git a/mingw-w64-python/0143-Build-and-install-libpython3.dll.patch b/mingw-w64-python/0143-Build-and-install-libpython3.dll.patch new file mode 100644 index 0000000000000..8c10256cc4940 --- /dev/null +++ b/mingw-w64-python/0143-Build-and-install-libpython3.dll.patch @@ -0,0 +1,108 @@ +From 8aeb46d09c068a1228e83b29101c17bf1ff0612a Mon Sep 17 00:00:00 2001 +From: Christoph Reiter +Date: Mon, 21 Aug 2023 08:19:28 +0200 +Subject: [PATCH 143/N] Build and install libpython3.dll + +This provides the limited ABI as a separate DLL, forwarding to the +real one. This makes linking with "-lpython3" work. + +Fixes #147 +--- + Makefile.pre.in | 15 +++++++++++++-- + PC/python3dll.c | 8 ++++++++ + 2 files changed, 21 insertions(+), 2 deletions(-) + +diff --git a/Makefile.pre.in b/Makefile.pre.in +index d5a9e2b..4fa310e 100644 +--- a/Makefile.pre.in ++++ b/Makefile.pre.in +@@ -278,6 +278,8 @@ LIBRARY_DEPS= @LIBRARY_DEPS@ + LINK_PYTHON_DEPS=@LINK_PYTHON_DEPS@ + PY_ENABLE_SHARED= @PY_ENABLE_SHARED@ + STATIC_LIBPYTHON= @STATIC_LIBPYTHON@ ++ABI3DLLLIBRARY= libpython3.dll ++ABI3LDLIBRARY= libpython3.dll.a + + + LIBS= @LIBS@ +@@ -600,7 +602,7 @@ LIBEXPAT_HEADERS= \ + # Default target + all: @DEF_MAKE_ALL_RULE@ + build_all: check-clean-src $(BUILDPYTHON) $(BUILDPYTHONW) $(BUILDVENVLAUNCHER) $(BUILDVENVWLAUNCHER) platform oldsharedmods sharedmods \ +- gdbhooks Programs/_testembed python-config ++ gdbhooks Programs/_testembed python-config $(ABI3DLLLIBRARY) $(ABI3LDLIBRARY) + build_wasm: check-clean-src $(BUILDPYTHON) platform oldsharedmods python-config + + # Check that the source is clean when building out of source. +@@ -724,6 +726,9 @@ pythonw_exe.o: $(srcdir)/PC/pythonw_exe.rc + python_nt.o: $(srcdir)/PC/python_nt.rc + $(WINDRES) $(RCFLAGS) -DORIGINAL_FILENAME=\\\"$(DLLLIBRARY)\\\" -I$(srcdir)/Include -I$(srcdir)/PC -I. $(srcdir)/PC/python_nt.rc $@ + ++python3dll_nt.o: $(srcdir)/PC/python_nt.rc ++ $(WINDRES) $(RCFLAGS) -DORIGINAL_FILENAME=\\\"$(ABI3DLLLIBRARY)\\\" -I$(srcdir)/Include -I$(srcdir)/PC -I. $(srcdir)/PC/python_nt.rc $@ ++ + venvlauncher.o: $(srcdir)/PC/pylauncher.rc + $(WINDRES) $(RCFLAGS) -DPY_ICON -I$(srcdir)/Include -I$(srcdir)/PC -I. $(srcdir)/PC/pylauncher.rc $@ + +@@ -852,6 +857,10 @@ $(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS) python_nt.o + else true; \ + fi + ++$(ABI3DLLLIBRARY) $(ABI3LDLIBRARY): python3dll_nt.o $(srcdir)/PC/launcher.c ++ $(LDSHARED) -DPYTHON_DLL_NAME=\"$(DLLLIBRARY)\" $(srcdir)/PC/python3dll.c -Wl,--out-implib=$(ABI3LDLIBRARY) -o $(ABI3DLLLIBRARY) python3dll_nt.o \ ++ $(LDFLAGS_NODIST); ++ + # wasm32-emscripten browser build + # wasm assets directory is relative to current build dir, e.g. "./usr/local". + # --preload-file turns a relative asset path into an absolute path. +@@ -1863,6 +1872,7 @@ altbininstall: $(BUILDPYTHON) @FRAMEWORKPYTHONW@ + if test -f $(LDLIBRARY) && test "$(PYTHONFRAMEWORKDIR)" = "no-framework" ; then \ + if test -n "$(DLLLIBRARY)" ; then \ + $(INSTALL_SHARED) $(DLLLIBRARY) $(DESTDIR)$(BINDIR); \ ++ $(INSTALL_SHARED) $(ABI3DLLLIBRARY) $(DESTDIR)$(BINDIR); \ + else \ + $(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \ + if test $(LDLIBRARY) != $(INSTSONAME); then \ +@@ -2275,6 +2285,7 @@ libainstall: all python-config + if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \ + if test "$(SHLIB_SUFFIX)" = .dll -o "$(SHLIB_SUFFIX)" = .pyd; then \ + $(INSTALL_DATA) $(LDLIBRARY) $(DESTDIR)$(LIBDIR) ; \ ++ $(INSTALL_DATA) $(ABI3LDLIBRARY) $(DESTDIR)$(LIBDIR) ; \ + else \ + $(INSTALL_DATA) $(LIBRARY) $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \ + fi; \ +@@ -2521,7 +2532,7 @@ clean: clean-retain-profile + fi + + clobber: clean +- -rm -f $(BUILDPYTHON) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \ ++ -rm -f $(BUILDPYTHON) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY)$(ABI3LDLIBRARY) $(ABI3DLLLIBRARY) \ + tags TAGS \ + config.cache config.log pyconfig.h Modules/config.c + -rm -rf build platform +diff --git a/PC/python3dll.c b/PC/python3dll.c +index 50e7a96..8b524fd 100755 +--- a/PC/python3dll.c ++++ b/PC/python3dll.c +@@ -3,6 +3,7 @@ + + /* Generated by Tools/scripts/stable_abi.py */ + ++#ifdef _MSC_VER + #ifdef _M_IX86 + #define DECORATE "_" + #else +@@ -13,6 +14,13 @@ + __pragma(comment(linker, "/EXPORT:" DECORATE #name "=" PYTHON_DLL_NAME "." #name)) + #define EXPORT_DATA(name) \ + __pragma(comment(linker, "/EXPORT:" DECORATE #name "=" PYTHON_DLL_NAME "." #name ",DATA")) ++#else ++// XXX: Why do we need the .dll extension and no DECORATE compared to the MSVC case? ++#define EXPORT_FUNC(name) \ ++ asm(".section .drectve\n\t.ascii \" -export:" #name "=\\\"" PYTHON_DLL_NAME "." #name "\\\" \""); ++#define EXPORT_DATA(name) \ ++ asm(".section .drectve\n\t.ascii \" -export:" #name "=\\\"" PYTHON_DLL_NAME "." #name "\\\",DATA \""); ++#endif + + EXPORT_FUNC(_Py_BuildValue_SizeT) + EXPORT_FUNC(_Py_CheckRecursiveCall) diff --git a/mingw-w64-python/PKGBUILD b/mingw-w64-python/PKGBUILD index 65e955c4fd752..45bcf187d813a 100644 --- a/mingw-w64-python/PKGBUILD +++ b/mingw-w64-python/PKGBUILD @@ -22,7 +22,7 @@ else pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}${_pybasever}") fi pkgver=${_pybasever}.4 -pkgrel=5 +pkgrel=6 pkgdesc="A high-level scripting language (mingw-w64)" arch=('any') mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64') @@ -188,7 +188,9 @@ source=("https://www.python.org/ftp/python/${pkgver%rc?}/Python-${pkgver}.tar.xz 0138-getpath-use-normpath-on-all-generated-paths.patch 0139-pathconfig-normpath-sys.path-0.patch 0140-smoketests-add-some-tests-for-sys-site-paths.patch - 0141-Search-DLLs-only-on-paths-added-using-add_dll_direct.patch) + 0141-Search-DLLs-only-on-paths-added-using-add_dll_direct.patch + 0142-Allow-picking-up-include-lib-dirs-from-CFLAGS-LDFLAG.patch + 0143-Build-and-install-libpython3.dll.patch) # Helper macros to help make tasks easier # apply_patch_with_msg() { @@ -342,7 +344,9 @@ prepare() { 0138-getpath-use-normpath-on-all-generated-paths.patch \ 0139-pathconfig-normpath-sys.path-0.patch \ 0140-smoketests-add-some-tests-for-sys-site-paths.patch \ - 0141-Search-DLLs-only-on-paths-added-using-add_dll_direct.patch + 0141-Search-DLLs-only-on-paths-added-using-add_dll_direct.patch \ + 0142-Allow-picking-up-include-lib-dirs-from-CFLAGS-LDFLAG.patch \ + 0143-Build-and-install-libpython3.dll.patch autoreconf -vfi } @@ -584,4 +588,6 @@ sha256sums=('2f0e409df2ab57aa9fc4cbddfb976af44e4e55bf6f619eee6bc5c2297264a7f6' '87c6d54604d60bb097a21723e89fbc7c0ebaf9f0de169613af79f09cd02b1554' '66adf06f722cd36780b066a561c804f99202d2d0a83c877e7ddeda8d47ce1c64' '630de3ac36b8eb96d556d6ce418629f0834530a801d7c72c7565d642f5208447' - '8b579b27e350e06b28112163c0996a8d4da8f5f57210141581c2adf2501f0d2f') + '8b579b27e350e06b28112163c0996a8d4da8f5f57210141581c2adf2501f0d2f' + 'dd25e84eff5c1500491ea65fde5deb63b60fa317232c11cf67a1f7196f9f7b0b' + '33fd114796d9bd91d00e98b40a953248aaa1f52e8c3609209211541292bf1de9')