Skip to content

Commit

Permalink
Detect and use MSVC compiler if available for preprocessing.
Browse files Browse the repository at this point in the history
Autogen has to be invoked from the MSVC command line so that cl.exe is in path.
  • Loading branch information
KubaO committed Jun 20, 2023
1 parent cac9083 commit 433908e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion hpy/tools/autogen/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,26 @@ class HPyAPI:
re.DOTALL | re.MULTILINE)

def __init__(self, filename):
cpp_cmd = get_config_var('CC').split(' ')
cpp_cmd = get_config_var('CC')
if cpp_cmd:
cpp_cmd = cpp_cmd.split(' ')
elif sys.platform == 'win32':
cpp_cmd = [shutil.which("cl.exe")]
if sys.platform == 'win32':
cpp_cmd += ['/E', '/I%s' % CURRENT_DIR]
else:
cpp_cmd += ['-E', '-I%s' % CURRENT_DIR]

msvc = "cl.exe" in cpp_cmd[0].casefold()

csource = pycparser.preprocess_file(filename,
cpp_path=str(cpp_cmd[0]),
cpp_args=cpp_cmd[1:])

# MSVC preprocesses _Pragma(foo) to __pragma(foo)
if msvc:
csource = re.sub(r'__pragma\(([^)]+)\)', r'#pragma \1\n', csource)

# Remove comments. NOTE: this assumes that comments are never inside
# string literals, but there shouldn't be any here.
def replace_keeping_newlines(m):
Expand Down

0 comments on commit 433908e

Please sign in to comment.