Skip to content

Commit d1c52a4

Browse files
committed
python/src/moocore/_ffi_build.py: Add -march= to link flags. Handle DEBUG.
1 parent 027dd30 commit d1c52a4

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

python/src/moocore/_ffi_build.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import platform
1313
from cffi import FFI
1414

15+
DEBUG = 0 # Compile in debug mode.
16+
1517
libmoocore_h = "src/moocore/libmoocore.h"
1618
sources_path = "src/moocore/libmoocore/"
1719
headers = """
@@ -82,20 +84,20 @@ def _get_target_platform():
8284
MSVC_CFLAGS = ["/GL", "/O2", "/GS-", "/wd4996", "/DMOOCORE_SHARED_LIB"]
8385
MSVC_LDFLAGS = ["/LTCG"]
8486
GCC_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

8693
extra_compile_args = []
8794
extra_link_args = []
8895
if 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")
9398
else:
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

100102
cflags = os.environ.get("CFLAGS", "")
101103
if cflags != "":
@@ -111,16 +113,20 @@ def _get_target_platform():
111113
with 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

115119
ffibuilder.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

125131
if __name__ == "__main__":
126-
ffibuilder.compile(verbose=True)
132+
ffibuilder.compile(verbose=True, debug=bool(DEBUG))

0 commit comments

Comments
 (0)