Skip to content

Commit

Permalink
Fix cross-platform compilation using `distutils._msvccompiler.MSVCCom…
Browse files Browse the repository at this point in the history
…piler`

Merge pull request #298 from Avasam/MSVCCompiler-cross-platform-bug
  • Loading branch information
jaraco authored Sep 15, 2024
2 parents 3ac1adc + f15beb8 commit 47353c5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion distutils/_msvccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def initialize(self, plat_name=None):
f"--plat-name must be one of {tuple(_vcvars_names)}"
)

plat_spec = _get_vcvars_spec(get_host_platform(), get_platform())
plat_spec = _get_vcvars_spec(get_host_platform(), plat_name)

vc_env = _get_vc_env(plat_spec)
if not vc_env:
Expand Down
26 changes: 26 additions & 0 deletions distutils/tests/test_msvccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import os
import sys
import sysconfig
import threading
import unittest.mock as mock
from distutils import _msvccompiler
from distutils.errors import DistutilsPlatformError
from distutils.tests import support
from distutils.util import get_platform

import pytest

Expand All @@ -28,6 +30,30 @@ def _find_vcvarsall(plat_spec):
'wont find this version',
)

@pytest.mark.skipif(
not sysconfig.get_platform().startswith("win"),
reason="Only run test for non-mingw Windows platforms",
)
@pytest.mark.parametrize(
"plat_name, expected",
[
("win-arm64", "win-arm64"),
("win-amd64", "win-amd64"),
(None, get_platform()),
],
)
def test_cross_platform_compilation_paths(self, monkeypatch, plat_name, expected):
"""
Ensure a specified target platform is passed to _get_vcvars_spec.
"""
compiler = _msvccompiler.MSVCCompiler()

def _get_vcvars_spec(host_platform, platform):
assert platform == expected

monkeypatch.setattr(_msvccompiler, '_get_vcvars_spec', _get_vcvars_spec)
compiler.initialize(plat_name)

@needs_winreg
def test_get_vc_env_unicode(self):
test_var = 'ṰḖṤṪ┅ṼẨṜ'
Expand Down
1 change: 1 addition & 0 deletions newsfragments/298.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix cross-platform compilation using ``distutils._msvccompiler.MSVCCompiler`` -- by :user:`saschanaz` and :user:`Avasam`

0 comments on commit 47353c5

Please sign in to comment.