From 24d61aaeaba52fcba2f6c8fe6bed665c1b5b9895 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Wed, 20 Sep 2023 21:10:48 -0500 Subject: [PATCH] Detect MSVC version and architecture via preprocessor --- scripts/dev.py | 20 ++++++++++++++------ scripts/msvc_version.txt | 9 +++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 scripts/msvc_version.txt diff --git a/scripts/dev.py b/scripts/dev.py index c8531c2..390ca4d 100644 --- a/scripts/dev.py +++ b/scripts/dev.py @@ -408,22 +408,30 @@ def ensure_programs(): if platform.system() == "Windows": MSVC_MAJOR, MSVC_MINOR = 19, 35 try: - result = subprocess.run(["cl"], capture_output=True, text=True) - if "for x64" not in result.stderr: + cl_only = subprocess.run(["cl"], capture_output=True, text=True) + desc = cl_only.stderr.splitlines()[0] + + detect = subprocess.run(["cl", "/EP", "scripts\\msvc_version.txt"], capture_output=True, text=True) + parts = [x for x in detect.stdout.splitlines() if x] + version, arch = int(parts[0]), parts[1] + major, minor = int(version / 100), version % 100 + + if arch != "x64": msg = log_error("MSVC is not running in 64-bit mode. Make sure you are running in") msg.more("an x64 Visual Studio command prompt, such as the \"x64 Native Tools") msg.more("Command Prompt\" from your Start Menu.") msg.more() msg.more("MSVC reported itself as:") - msg.more(result.stderr.splitlines()[0]) + msg.more(desc) exit(1) - m = re.search(r"Version (\d+)\.(\d+).(\d+)", result.stderr) - major, minor, patch = int(m.group(1)), int(m.group(2)), int(m.group(3)) if major < MSVC_MAJOR or minor < MSVC_MINOR: - msg = log_error(f"Your version of MSVC is too old. You have version {major}.{minor}.{patch},") + msg = log_error(f"Your version of MSVC is too old. You have version {major}.{minor},") msg.more(f"but version {MSVC_MAJOR}.{MSVC_MINOR} or greater is required.") msg.more() + msg.more("MSVC reported itself as:") + msg.more(desc) + msg.more() msg.more("Please update Visual Studio to the latest version and try again.") exit(1) except FileNotFoundError: diff --git a/scripts/msvc_version.txt b/scripts/msvc_version.txt new file mode 100644 index 0000000..42e4f30 --- /dev/null +++ b/scripts/msvc_version.txt @@ -0,0 +1,9 @@ +_MSC_VER + +#if defined(__x86_64__) || defined(_M_X64) +x64 +#elif defined(i386) || defined(__i386__) || defined(__i386) || defined(_M_IX86) +x86 +#else +unknown +#endif -- 2.25.1