summarylogtreecommitdiffstats
path: root/0086-distutils-MINGW-build-extensions-with-GCC.patch
blob: ee576d1c547e74ff208072c5a3109191f8280ce3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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.33.0