Skip to content

Fixed build_ext assumption that cross-compilation on Windows always uses MSVCCompiler#399

Merged
jaraco merged 2 commits into
pypa:mainfrom
Avasam:patch-1
Jul 7, 2026
Merged

Fixed build_ext assumption that cross-compilation on Windows always uses MSVCCompiler#399
jaraco merged 2 commits into
pypa:mainfrom
Avasam:patch-1

Conversation

@Avasam

@Avasam Avasam commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Fixes the following error if providing --plat-name when using msys2-mingw on Windows:

Traceback (most recent call last):
  File "D:/a/_temp/msys64/mingw64/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
    main()
  File "D:/a/_temp/msys64/mingw64/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in main
    json_out["return_val"] = hook(**hook_input["kwargs"])
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:/a/_temp/msys64/mingw64/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 280, in build_wheel
    return _build_backend().build_wheel(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/build_meta.py", line 438, in build_wheel
    return _build(['bdist_wheel'])
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/build_meta.py", line 429, in _build
    return self._build_with_temp_dir(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/build_meta.py", line 410, in _build_with_temp_dir
    self.run_setup()
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/build_meta.py", line 317, in run_setup
    exec(code, locals())
  File "<string>", line 1963, in <module>
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/__init__.py", line 117, in setup
    return distutils.core.setup(**attrs)  # type: ignore[return-value]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 186, in setup
    return run_commands(dist)
           ^^^^^^^^^^^^^^^^^^
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 202, in run_commands
    dist.run_commands()
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1000, in run_commands
    self.run_command(cmd)
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/dist.py", line 1107, in run_command
    super().run_command(command)
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1019, in run_command
    cmd_obj.run()
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/command/bdist_wheel.py", line 370, in run
    self.run_command("build")
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 341, in run_command
    self.distribution.run_command(command)
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/dist.py", line 1107, in run_command
    super().run_command(command)
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1019, in run_command
    cmd_obj.run()
  File "<string>", line 354, in run
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/command/build.py", line 135, in run
    self.run_command(cmd_name)
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 341, in run_command
    self.distribution.run_command(command)
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/dist.py", line 1107, in run_command
    super().run_command(command)
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1019, in run_command
    cmd_obj.run()
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/command/build_ext.py", line 97, in run
    _build_ext.run(self)
  File "D:/a/_temp/msys64/tmp/build-env-g6pjoax9/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 336, in run
    self.compiler.initialize(self.plat_name)
    ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'MinGW32Compiler' object has no attribute 'initialize'

This could've been caught with static type checking, but attr-defined is currently disabled in mypy

Comment thread distutils/command/build_ext.py Outdated
…or non-MSVC compilers

build_ext.run() unconditionally called compiler.initialize() when
cross-compiling on Windows, assuming an MSVCCompiler. With any other
compiler (e.g. MinGW/msys2) this raised AttributeError.

Rather than guard the call with hasattr(), give the base Compiler a no-op
initialize() that non-MSVC compilers inherit; MSVCCompiler continues to
override it. This also makes the method visible to static type checkers.
The redundant os.name == 'nt' guard is dropped since initialize() is now
safe on every compiler.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jaraco jaraco merged commit 8f341ca into pypa:main Jul 7, 2026
22 checks passed
@Avasam Avasam deleted the patch-1 branch July 7, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants