From 4a3406baf94b1ef8122364b417c9564344a52921 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Thu, 4 Jul 2024 22:53:21 +0200 Subject: [PATCH 1/3] CI: also set CC/CXX when pip installing with mingw+clang Now that setuptools with mingw support is on pypi, this uncovered the same issue as fixed in 23174730a61af359f when pip installing MarkupSafe. Apply the same work around here too. --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b6b757dbf5..1f63867d85 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -143,6 +143,9 @@ jobs: git - name: Install Dependencies shell: msys2 {0} + env: + CC: ${{ matrix.cc }} + CXX: ${{ matrix.cxx }} run: | export VIRTUALENV_NO_SETUPTOOLS=1 From bacd9c6f92ed1926644f5743d7139d16ee65801b Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Thu, 4 Jul 2024 22:25:54 +0200 Subject: [PATCH 2/3] sysconfig: skip customize_compiler() with MSVC Python again By enabling customize_compiler() when using the mingw compiler class in 2ad8784dfeb81682 this also enabled it for when the mingw compiler class was used with a MSVC built CPython. MSVC CPython doesn't have any of the config vars that are required in customize_compiler() though. And while it would be nice if all the env vars would be considered in that scenario too, it's not clear how this should be implemented without any sysconfig provided fallbacks (if CC isn't set but CFLAGS is, there is no way to pass things to set_executables() etc.) Given that, just restore the previous behaviour, skip customize_compiler() with MSVC Python in all cases, and add a test. Fixes https://github.com/pypa/setuptools/issues/4456 --- distutils/sysconfig.py | 4 +++- distutils/tests/test_mingwccompiler.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/distutils/sysconfig.py b/distutils/sysconfig.py index 4ba0be5602..7ebe67687e 100644 --- a/distutils/sysconfig.py +++ b/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/distutils/tests/test_mingwccompiler.py b/distutils/tests/test_mingwccompiler.py index d81360e782..fd201cd773 100644 --- a/distutils/tests/test_mingwccompiler.py +++ b/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) From c4e64c194285e73895a858fa226cd5225beebfed Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 9 Jul 2024 11:44:04 -0400 Subject: [PATCH 3/3] Add news fragment. --- newsfragments/+4571b0f4.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/+4571b0f4.bugfix.rst 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