From 5b90f4c733e8137144e8aaf23b5b0832a5c0e173 Mon Sep 17 00:00:00 2001 From: Aohan Dang Date: Fri, 9 Aug 2024 15:17:37 -0400 Subject: [PATCH] Warn if vendored Microsoft Visual C++ runtime is too old --- delvewheel/_dll_list.py | 4 ++++ delvewheel/_dll_utils.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/delvewheel/_dll_list.py b/delvewheel/_dll_list.py index 08c09be..af87467 100644 --- a/delvewheel/_dll_list.py +++ b/delvewheel/_dll_list.py @@ -97,6 +97,10 @@ def platform_tag_to_type(cls, tag: str) -> typing.Optional['MachineType']: # Set of regular expressions of DLLs whose names should not be mangled. no_mangle_regexes = {} +# Regular expression that matches Microsoft Visual C++ runtime redistributable +# files +vc_redist = re.compile(r'((vcruntime\d.*)|(vccorlib\d.*)|(msvcp[\d_].*)|(msvcr(t|\d.*))|(concrt\d.*)|(mfc(m(ifc)?)?\d.*)|(vcamp\d.*)|(vcomp(\d.*|))|ucrtbase(d|_.*|))\.dll') + # ignore_names_x86 is a set containing the lowercase names of all DLLs that can # be assumed to be present on 32-bit x86 Windows 7 SP1 or later. These are all # the files with extension .dll or .drv found in C:\Windows\SysWOW64 on vanilla diff --git a/delvewheel/_dll_utils.py b/delvewheel/_dll_utils.py index ffb42fa..2adcf6f 100644 --- a/delvewheel/_dll_utils.py +++ b/delvewheel/_dll_utils.py @@ -6,6 +6,7 @@ import itertools import os import pathlib +import re import struct import subprocess import sys @@ -417,6 +418,14 @@ def get_all_needed(lib_path: str, if dll_info: stack.append(dll_info[0]) associated.update(dll_info[1]) + if re.fullmatch(_dll_list.vc_redist, dll_name): + linker_version = pe.OPTIONAL_HEADER.MajorLinkerVersion, pe.OPTIONAL_HEADER.MinorLinkerVersion + with PEContext(dll_info[0], None, False, verbose) as pe2: + vc_redist_version = pe2.OPTIONAL_HEADER.MajorLinkerVersion, pe2.OPTIONAL_HEADER.MinorLinkerVersion + if linker_version > vc_redist_version: + linker_version = f'{linker_version[0]}.{linker_version[1]}' + vc_redist_version = f'{vc_redist_version[0]}.{vc_redist_version[1]}' + warnings.warn(f'{os.path.basename(lib_path)} was built with a newer Microsoft Visual C++ runtime ({linker_version}) than the discovered {os.path.basename(dll_info[0])} ({vc_redist_version}). This may cause compatibility issues.') elif on_error == 'raise': raise FileNotFoundError(f'Unable to find library: {dll_name}') else: