From 2ef94a71f8072567e39f22bfed7bcae0ca2038c2 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 15 Dec 2022 16:32:14 -0500 Subject: [PATCH] delay importing ctypes unless it is actually used ctypes uses FFI, and surprisingly often people's Python installations will be broken because ctypes is broken (e.g. the system libffi has been updated and Python needs to be recompiled). That is not our fault, but it does manifest as Meson failing to run. It turns out we aren't even using it though. At least, pretty often. We have two uses of ctypes, and both of them are for Windows. One of them is already conditionally imported in the function that uses it, but the other is imported at startup. Move this down into the invoking function. On non-Windows systems, it is now impossible for Meson to fail to run when ctypes is broken, because we don't use it. Anecdotally, this issue tends to come up on Linux systems primarily. Fixes #11111 Closes #11112 --- mesonbuild/utils/universal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py index 220a7f486..a78ca7fd9 100644 --- a/mesonbuild/utils/universal.py +++ b/mesonbuild/utils/universal.py @@ -17,7 +17,6 @@ from __future__ import annotations from pathlib import Path import argparse -import ctypes import enum import sys import stat @@ -699,6 +698,7 @@ def windows_detect_native_arch() -> str: if sys.platform != 'win32': return '' try: + import ctypes process_arch = ctypes.c_ushort() native_arch = ctypes.c_ushort() kernel32 = ctypes.windll.kernel32