2
2
import shutil
3
3
import tokenize
4
4
import sys
5
+ import sysconfig
5
6
6
7
from typing import Optional , Tuple
7
8
22
23
MOD_DIR = pathlib .Path (__file__ ).parent
23
24
24
25
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
+
25
34
def compile_c_extension (
26
35
generated_source_path : str ,
27
36
build_dir : Optional [str ] = None ,
@@ -43,9 +52,8 @@ def compile_c_extension(
43
52
44
53
source_file_path = pathlib .Path (generated_source_path )
45
54
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' )
49
57
if keep_asserts :
50
58
extra_compile_args .append ("-UNDEBUG" )
51
59
extension = [
@@ -66,6 +74,7 @@ def compile_c_extension(
66
74
str (MOD_DIR .parent .parent .parent / "Parser" / "pegen" ),
67
75
],
68
76
extra_compile_args = extra_compile_args ,
77
+ extra_link_args = extra_link_args ,
69
78
)
70
79
]
71
80
dist = Distribution ({"name" : extension_name , "ext_modules" : extension })
0 commit comments