mirror of
https://github.com/dobin/SuperMega
synced 2026-06-02 17:27:10 +00:00
feature: wrong compiler friendly user error
This commit is contained in:
@@ -2,6 +2,7 @@ import os
|
||||
import pprint
|
||||
import logging
|
||||
import shutil
|
||||
import subprocess
|
||||
from typing import List, Dict
|
||||
|
||||
from helper import *
|
||||
@@ -16,6 +17,59 @@ from model.settings import Settings
|
||||
logger = logging.getLogger("Compiler")
|
||||
|
||||
|
||||
def check_compiler_architecture():
|
||||
"""Check if the Visual C++ compiler is configured for x64 architecture."""
|
||||
try:
|
||||
# Run cl.exe without arguments to get version info
|
||||
result = subprocess.run(
|
||||
[config.get("path_cl")],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=5
|
||||
)
|
||||
output = result.stderr # cl.exe outputs version info to stderr
|
||||
|
||||
# Check if it's x64 or x86
|
||||
if "x64" in output or "AMD64" in output:
|
||||
logger.info(" ✓ Compiler architecture: x64 (64-bit)")
|
||||
return True
|
||||
elif "x86" in output or "80x86" in output:
|
||||
logger.error(" ✗ Compiler architecture: x86 (32-bit) - INCORRECT!")
|
||||
logger.error("")
|
||||
logger.error("=" * 70)
|
||||
logger.error("ERROR: You are using a 32-bit compiler, but this tool requires 64-bit!")
|
||||
logger.error("=" * 70)
|
||||
logger.error("")
|
||||
logger.error("To fix this, you need to start the x64 Developer Command Prompt:")
|
||||
logger.error("")
|
||||
logger.error("Option 1 - Use the Start Menu:")
|
||||
logger.error(" 1. Open Start Menu")
|
||||
logger.error(" 2. Search for 'x64 Native Tools Command Prompt'")
|
||||
logger.error(" 3. Run it and then execute your script from there")
|
||||
logger.error("")
|
||||
logger.error("Option 2 - Run vcvarsall.bat in your current terminal:")
|
||||
logger.error(' "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat" x64')
|
||||
logger.error("")
|
||||
logger.error("Option 3 - If using VS 2019 or different installation path:")
|
||||
logger.error(' "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat" x64')
|
||||
logger.error("")
|
||||
logger.error("After running one of these, try again!")
|
||||
logger.error("=" * 70)
|
||||
return False
|
||||
else:
|
||||
logger.warning(" ? Could not determine compiler architecture")
|
||||
logger.warning(" Compiler output: {}".format(output[:200]))
|
||||
return True # Don't block if we can't determine
|
||||
|
||||
except FileNotFoundError:
|
||||
logger.error(" ✗ Compiler (cl.exe) not found at: {}".format(config.get("path_cl")))
|
||||
logger.error(" Make sure Visual Studio is installed and Developer Command Prompt is active")
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.warning(" ? Could not check compiler architecture: {}".format(e))
|
||||
return True # Don't block on unexpected errors
|
||||
|
||||
|
||||
# NOTE: Mostly copy-pasted from compiler.py::compile()
|
||||
def compile_dev(
|
||||
c_in: FilePath,
|
||||
@@ -30,6 +84,7 @@ def compile_dev(
|
||||
"/c",
|
||||
"/FA",
|
||||
"/GS-",
|
||||
"/favor:AMD64",
|
||||
"/Fa{}/".format(os.path.dirname(c_in)),
|
||||
c_in,
|
||||
])
|
||||
@@ -59,6 +114,10 @@ def compile(
|
||||
logger.info("-[ Carrier: Compile C to ASM".format())
|
||||
logger.info(" Carrier: {} -> {} ".format(c_in, asm_out))
|
||||
|
||||
# Check if we're using the correct 64-bit compiler
|
||||
if not check_compiler_architecture():
|
||||
raise RuntimeError("Incorrect compiler architecture detected. Please use x64 Developer Command Prompt.")
|
||||
|
||||
# Compile C To Assembly (text)
|
||||
run_process_checkret([
|
||||
config.get("path_cl"),
|
||||
|
||||
Reference in New Issue
Block a user