diff --git a/newsfragments/+4571b0f4.bugfix.rst b/newsfragments/+4571b0f4.bugfix.rst new file mode 100644 index 0000000000..94c7cacdb7 --- /dev/null +++ b/newsfragments/+4571b0f4.bugfix.rst @@ -0,0 +1 @@ +Bugfix for building Cython extension on Windows (pypa/distutils#268). \ No newline at end of file diff --git a/setuptools/_distutils/sysconfig.py b/setuptools/_distutils/sysconfig.py index 4ba0be5602..7ebe67687e 100644 --- a/setuptools/_distutils/sysconfig.py +++ b/setuptools/_distutils/sysconfig.py @@ -293,7 +293,9 @@ def customize_compiler(compiler): # noqa: C901 Mainly needed on Unix, so we can plug in the information that varies across Unices and is stored in Python's Makefile. """ - if compiler.compiler_type in ["unix", "cygwin", "mingw32"]: + if compiler.compiler_type in ["unix", "cygwin"] or ( + compiler.compiler_type == "mingw32" and is_mingw() + ): _customize_macos() ( diff --git a/setuptools/_distutils/tests/test_mingwccompiler.py b/setuptools/_distutils/tests/test_mingwccompiler.py index d81360e782..fd201cd773 100644 --- a/setuptools/_distutils/tests/test_mingwccompiler.py +++ b/setuptools/_distutils/tests/test_mingwccompiler.py @@ -2,6 +2,7 @@ from distutils.util import split_quoted, is_mingw from distutils.errors import DistutilsPlatformError, CCompilerError +from distutils import sysconfig class TestMingw32CCompiler: @@ -43,3 +44,12 @@ def test_cygwincc_error(self, monkeypatch): with pytest.raises(CCompilerError): distutils.cygwinccompiler.Mingw32CCompiler() + + def test_customize_compiler_with_msvc_python(self): + from distutils.cygwinccompiler import Mingw32CCompiler + + # In case we have an MSVC Python build, but still want to use + # Mingw32CCompiler, then customize_compiler() shouldn't fail at least. + # https://github.com/pypa/setuptools/issues/4456 + compiler = Mingw32CCompiler() + sysconfig.customize_compiler(compiler)