1212import platform
1313from cffi import FFI
1414
15+ DEBUG = 0 # Compile in debug mode.
16+
1517libmoocore_h = "src/moocore/libmoocore.h"
1618sources_path = "src/moocore/libmoocore/"
1719headers = """
@@ -82,20 +84,20 @@ def _get_target_platform():
8284MSVC_CFLAGS = ["/GL" , "/O2" , "/GS-" , "/wd4996" , "/DMOOCORE_SHARED_LIB" ]
8385MSVC_LDFLAGS = ["/LTCG" ]
8486GCC_CFLAGS = ["-O3" , "-flto" ]
87+ if is_x86_64 :
88+ # Compile for sufficiently old x86-64 architecture.
89+ MSVC_CFLAGS += ["/arch:AVX" ]
90+ MSVC_LDFLAGS += ["/arch:AVX" ]
91+ GCC_CFLAGS += ["-march=x86-64-v2" ]
8592
8693extra_compile_args = []
8794extra_link_args = []
8895if is_windows and uses_msvc ():
8996 extra_compile_args .extend (MSVC_CFLAGS )
9097 extra_link_args .extend (MSVC_LDFLAGS )
91- if is_x86_64 :
92- extra_compile_args .append ("/arch:AVX" )
9398else :
9499 extra_compile_args .extend (GCC_CFLAGS )
95100 extra_link_args .extend (GCC_CFLAGS )
96- # Compile for sufficiently old x86-64 architecture.
97- if is_x86_64 :
98- extra_compile_args .append ("-march=x86-64-v2" )
99101
100102cflags = os .environ .get ("CFLAGS" , "" )
101103if cflags != "" :
@@ -111,16 +113,20 @@ def _get_target_platform():
111113with open (libmoocore_h ) as f :
112114 ffibuilder .cdef (f .read ())
113115
116+ # This is not done automatically by ffibuilder.compile(debug=True) !
117+ undef_macros = ["NDEBUG" ] if DEBUG >= 1 else []
114118
115119ffibuilder .set_source (
116120 "moocore._libmoocore" ,
117121 headers ,
118122 sources = sources ,
123+ define_macros = [("DEBUG" , str (DEBUG ))],
124+ undef_macros = undef_macros ,
119125 include_dirs = [libmoocore_path ],
120126 extra_compile_args = extra_compile_args ,
121127 extra_link_args = extra_link_args ,
122128 py_limited_api = True , # build against the stable ABI (abi3)
123129)
124130
125131if __name__ == "__main__" :
126- ffibuilder .compile (verbose = True )
132+ ffibuilder .compile (verbose = True , debug = bool ( DEBUG ) )
0 commit comments