22import shutil
33import tokenize
44import sys
5+ import sysconfig
56
67from typing import Optional , Tuple
78
2223MOD_DIR = pathlib .Path (__file__ ).parent
2324
2425
26+ def get_extra_flags (compiler_flags , compiler_py_flags_nodist ):
27+ flags = sysconfig .get_config_var (compiler_flags )
28+ py_flags_nodist = sysconfig .get_config_var (compiler_py_flags_nodist )
29+ if flags is None or py_flags_nodist is None :
30+ return []
31+ return f'{ flags } { py_flags_nodist } ' .split ()
32+
33+
2534def compile_c_extension (
2635 generated_source_path : str ,
2736 build_dir : Optional [str ] = None ,
@@ -43,9 +52,8 @@ def compile_c_extension(
4352
4453 source_file_path = pathlib .Path (generated_source_path )
4554 extension_name = source_file_path .stem
46- extra_compile_args = []
47- if not sys .platform .startswith ('win' ):
48- extra_compile_args .append ("-std=c99" )
55+ extra_compile_args = get_extra_flags ('CFLAGS' , 'PY_CFLAGS_NODIST' )
56+ extra_link_args = get_extra_flags ('LDFLAGS' , 'PY_LDFLAGS_NODIST' )
4957 if keep_asserts :
5058 extra_compile_args .append ("-UNDEBUG" )
5159 extension = [
@@ -66,6 +74,7 @@ def compile_c_extension(
6674 str (MOD_DIR .parent .parent .parent / "Parser" / "pegen" ),
6775 ],
6876 extra_compile_args = extra_compile_args ,
77+ extra_link_args = extra_link_args ,
6978 )
7079 ]
7180 dist = Distribution ({"name" : extension_name , "ext_modules" : extension })
0 commit comments