Skip to content

Commit d4a685a

Browse files
lazkajaraco
authored andcommitted
mingw: make get_msvcr() a noop
This was added back in the day to make mingw use the same CRT as CPython (https://bugs.python.org/issue870382), but at least with newer mingw-w64 and ucrt switching the CRT at "runtime" isn't supported anymore. To build a compatible extension you have to use a ucrt mingw-w64 build, so things match up and link against the same CRT. CPython 3.5+ uses ucrt (see https://wiki.python.org/moin/WindowsCompilers), so anything besides that is no longer relevant, which only leaves vcruntime140. Since it's not clear what linking against vcruntime140 solves, and there have been reports of it needing to be patched out: * pypa#4101 * pypa/distutils#204 (comment) let's just make it return nothing. Keep get_msvcr() around for now to avoid breaking code which patched it. Fixes pypa#204
1 parent d13da58 commit d4a685a

File tree

2 files changed

+2
-80
lines changed

2 files changed

+2
-80
lines changed

distutils/cygwinccompiler.py

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
import copy
1010
import os
1111
import pathlib
12-
import re
1312
import shlex
1413
import sys
1514
import warnings
1615
from subprocess import check_output
1716

18-
from ._collections import RangeMap
1917
from .errors import (
2018
CCompilerError,
2119
CompileError,
@@ -26,42 +24,10 @@
2624
from .unixccompiler import UnixCCompiler
2725
from .version import LooseVersion, suppress_known_deprecation
2826

29-
_msvcr_lookup = RangeMap.left(
30-
{
31-
# MSVC 7.0
32-
1300: ['msvcr70'],
33-
# MSVC 7.1
34-
1310: ['msvcr71'],
35-
# VS2005 / MSVC 8.0
36-
1400: ['msvcr80'],
37-
# VS2008 / MSVC 9.0
38-
1500: ['msvcr90'],
39-
# VS2010 / MSVC 10.0
40-
1600: ['msvcr100'],
41-
# VS2012 / MSVC 11.0
42-
1700: ['msvcr110'],
43-
# VS2013 / MSVC 12.0
44-
1800: ['msvcr120'],
45-
# VS2015 / MSVC 14.0
46-
1900: ['vcruntime140'],
47-
2000: RangeMap.undefined_value,
48-
},
49-
)
50-
5127

5228
def get_msvcr():
53-
"""Include the appropriate MSVC runtime library if Python was built
54-
with MSVC 7.0 or later.
55-
"""
56-
match = re.search(r'MSC v\.(\d{4})', sys.version)
57-
try:
58-
msc_ver = int(match.group(1))
59-
except AttributeError:
60-
return []
61-
try:
62-
return _msvcr_lookup[msc_ver]
63-
except KeyError:
64-
raise ValueError(f"Unknown MS Compiler version {msc_ver} ")
29+
"""No longer needed, but kept for backward compatibility."""
30+
return []
6531

6632

6733
_runtime_library_dirs_msg = (
@@ -109,8 +75,6 @@ def __init__(self, verbose=False, dry_run=False, force=False):
10975
linker_so=(f'{self.linker_dll} -mcygwin {shared_option}'),
11076
)
11177

112-
# Include the appropriate MSVC runtime library if Python was built
113-
# with MSVC 7.0 or later.
11478
self.dll_libraries = get_msvcr()
11579

11680
@property

distutils/tests/test_cygwinccompiler.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -71,50 +71,8 @@ def test_check_config_h(self):
7171
assert check_config_h()[0] == CONFIG_H_OK
7272

7373
def test_get_msvcr(self):
74-
# []
75-
sys.version = (
76-
'2.6.1 (r261:67515, Dec 6 2008, 16:42:21) '
77-
'\n[GCC 4.0.1 (Apple Computer, Inc. build 5370)]'
78-
)
7974
assert get_msvcr() == []
8075

81-
# MSVC 7.0
82-
sys.version = (
83-
'2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1300 32 bits (Intel)]'
84-
)
85-
assert get_msvcr() == ['msvcr70']
86-
87-
# MSVC 7.1
88-
sys.version = (
89-
'2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bits (Intel)]'
90-
)
91-
assert get_msvcr() == ['msvcr71']
92-
93-
# VS2005 / MSVC 8.0
94-
sys.version = (
95-
'2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1400 32 bits (Intel)]'
96-
)
97-
assert get_msvcr() == ['msvcr80']
98-
99-
# VS2008 / MSVC 9.0
100-
sys.version = (
101-
'2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1500 32 bits (Intel)]'
102-
)
103-
assert get_msvcr() == ['msvcr90']
104-
105-
sys.version = (
106-
'3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 18:46:30) '
107-
'[MSC v.1929 32 bit (Intel)]'
108-
)
109-
assert get_msvcr() == ['vcruntime140']
110-
111-
# unknown
112-
sys.version = (
113-
'2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.2000 32 bits (Intel)]'
114-
)
115-
with pytest.raises(ValueError):
116-
get_msvcr()
117-
11876
@pytest.mark.skipif('sys.platform != "cygwin"')
11977
def test_dll_libraries_not_none(self):
12078
from distutils.cygwinccompiler import CygwinCCompiler

0 commit comments

Comments
 (0)