Files
MINGW-packages/mingw-w64-python/0086-distutils-MINGW-build-extensions-with-GCC.patch
Christoph Reiter 914c8fd859 Update Python
2021-11-21 22:09:20 +01:00

61 lines
2.5 KiB
Diff

From bc18b4c3c94375ddff17aaf5a1bb5bd1e401997f Mon Sep 17 00:00:00 2001
From: Christoph Reiter <reiter.christoph@gmail.com>
Date: Tue, 21 Sep 2021 20:52:22 +0200
Subject: [PATCH 086/N] distutils: MINGW build extensions with GCC
---
Lib/distutils/command/build_ext.py | 16 +++++++++++++++-
Lib/distutils/util.py | 2 ++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
index 1a9bd12..1c9d471 100644
--- a/Lib/distutils/command/build_ext.py
+++ b/Lib/distutils/command/build_ext.py
@@ -186,7 +186,7 @@ class build_ext(Command):
# for extensions under windows use different directories
# for Release and Debug builds.
# also Python's library directory must be appended to library_dirs
- if os.name == 'nt':
+ if os.name == 'nt' and not self.plat_name.startswith(('mingw')):
# the 'libs' directory is for binary installs - we assume that
# must be the *native* platform. But we don't really support
# cross-compiling via a binary install anyway, so we let it go.
@@ -712,6 +712,20 @@ class build_ext(Command):
# pyconfig.h that MSVC groks. The other Windows compilers all seem
# to need it mentioned explicitly, though, so that's what we do.
# Append '_d' to the python import library on debug builds.
+
+ # Use self.plat_name as it works even in case of
+ # cross-compilation (at least for mingw build).
+ if self.plat_name.startswith('mingw'):
+ from distutils import sysconfig
+ extra = []
+ for lib in (
+ sysconfig.get_config_var('BLDLIBRARY').split()
+ + sysconfig.get_config_var('SHLIBS').split()
+ ):
+ if lib.startswith('-l'):
+ extra.append(lib[2:])
+ return ext.libraries + extra
+
if sys.platform == "win32":
from distutils._msvccompiler import MSVCCompiler
if not isinstance(self.compiler, MSVCCompiler):
diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py
index 4b002ec..7b2e1e0 100644
--- a/Lib/distutils/util.py
+++ b/Lib/distutils/util.py
@@ -36,6 +36,8 @@ def get_host_platform():
"""
if os.name == 'nt':
+ if 'GCC' in sys.version:
+ return 'mingw'
if 'amd64' in sys.version.lower():
return 'win-amd64'
if '(arm)' in sys.version.lower():
--
2.34.0