@@ -63,20 +63,35 @@ def _pack_std_jsonnet(self):
63
63
f .write ("," .join (str (x ) for x in stdlib ))
64
64
f .write (",0\n \n " )
65
65
66
- def build_extension (self , ext ):
66
+ def build_extensions (self ):
67
67
# At this point, the compiler has been chosen so we add compiler-specific flags.
68
68
# There is unfortunately no built in support for this in setuptools.
69
69
# Feature request: https://github.com/pypa/setuptools/issues/1819
70
-
71
- print ("Setting compile flags for compiler type " + self .compiler .compiler_type )
70
+ print ("Adjusting compiler for compiler type " + self .compiler .compiler_type )
72
71
# This is quite hacky as we're modifying the Extension object itself.
73
72
if self .compiler .compiler_type == "msvc" :
74
- ext .extra_compile_args .append ("/std:c++17" )
73
+ for ext in self .extensions :
74
+ ext .extra_compile_args .append ("/std:c++17" )
75
75
else :
76
- ext .extra_compile_args .append ("-std=c++17" )
77
-
78
- # Actually build.
79
- super ().build_extension (ext )
76
+ # -std=c++17 should only be applied to C++ build,
77
+ # not when compiling C source code. Unfortunately,
78
+ # the extra_compile_args applies to both. Instead,
79
+ # patch the CC/CXX commands in the compiler object.
80
+ #
81
+ # Note that older versions of distutils/setuptools do not
82
+ # have the necessary separation between C and C++ compilers.
83
+ # This requires setuptools 72.2.
84
+ for v in ("compiler_cxx" , "compiler_so_cxx" ):
85
+ if not hasattr (self .compiler , v ):
86
+ print (
87
+ f"WARNING: cannot adjust flag { v } , "
88
+ f"compiler type { self .compiler .compiler_type } , "
89
+ f"compiler class { type (self .compiler ).__name__ } "
90
+ )
91
+ continue
92
+ current = getattr (self .compiler , v )
93
+ self .compiler .set_executable (v , current + ["-std=c++17" ])
94
+ super ().build_extensions ()
80
95
81
96
def run (self ):
82
97
self ._pack_std_jsonnet ()
0 commit comments