Skip to content

Commit 7476962

Browse files
committed
distutils: MINGW build extensions with GCC
1 parent 923a3c5 commit 7476962

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Lib/distutils/command/build_ext.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def finalize_options(self):
186186
# for extensions under windows use different directories
187187
# for Release and Debug builds.
188188
# also Python's library directory must be appended to library_dirs
189-
if os.name == 'nt':
189+
if os.name == 'nt' and not self.plat_name.startswith(('mingw')):
190190
# the 'libs' directory is for binary installs - we assume that
191191
# must be the *native* platform. But we don't really support
192192
# cross-compiling via a binary install anyway, so we let it go.
@@ -712,6 +712,20 @@ def get_libraries(self, ext):
712712
# pyconfig.h that MSVC groks. The other Windows compilers all seem
713713
# to need it mentioned explicitly, though, so that's what we do.
714714
# Append '_d' to the python import library on debug builds.
715+
716+
# Use self.plat_name as it works even in case of
717+
# cross-compilation (at least for mingw build).
718+
if self.plat_name.startswith('mingw'):
719+
from distutils import sysconfig
720+
extra = []
721+
for lib in (
722+
sysconfig.get_config_var('BLDLIBRARY').split()
723+
+ sysconfig.get_config_var('SHLIBS').split()
724+
):
725+
if lib.startswith('-l'):
726+
extra.append(lib[2:])
727+
return ext.libraries + extra
728+
715729
if sys.platform == "win32":
716730
from distutils._msvccompiler import MSVCCompiler
717731
if not isinstance(self.compiler, MSVCCompiler):

Lib/distutils/util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def get_host_platform():
3737
3838
"""
3939
if os.name == 'nt':
40+
if 'GCC' in sys.version:
41+
return 'mingw'
4042
if 'amd64' in sys.version.lower():
4143
return 'win-amd64'
4244
if '(arm)' in sys.version.lower():

0 commit comments

Comments
 (0)