Skip to content

Commit

Permalink
distutils: MINGW build extensions with GCC
Browse files Browse the repository at this point in the history
  • Loading branch information
lazka committed Aug 25, 2023
1 parent 923a3c5 commit 7476962
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Lib/distutils/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def finalize_options(self):
# 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.
Expand Down Expand Up @@ -712,6 +712,20 @@ def get_libraries(self, ext):
# 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):
Expand Down
2 changes: 2 additions & 0 deletions Lib/distutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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():
Expand Down

0 comments on commit 7476962

Please sign in to comment.