From 9048a2dbab9a29ce92ff8270a860e2a1316f4f80 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Thu, 4 Jan 2018 23:10:40 +0100 Subject: [PATCH] Build from the installed deltachat version This cleans up the build somewhat: - Move time_t declaration to _build.py - Uses Python's distutils to invoke the "correct" compiler. Or at least does not make this code responsible to picking a compiler - Uses the compiler to find the installed header file, builds against this installed version. Since linking will also be against this installed version this seems to make some sense. This seems somewhat ugly though. --- python/src/deltachat/_build.py | 42 ++++++++++++++++++++++------------ src/mrmailbox.h | 7 ++---- src/mrmsg.h | 4 ---- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/python/src/deltachat/_build.py b/python/src/deltachat/_build.py index 65d00ce1..2a38fbac 100644 --- a/python/src/deltachat/_build.py +++ b/python/src/deltachat/_build.py @@ -1,23 +1,35 @@ -import subprocess +import distutils.ccompiler +import distutils.sysconfig import tempfile import cffi -ffibuilder = cffi.FFI() -ffibuilder.set_source( - 'deltachat.capi', - """ - #include - """, - libraries=['deltachat'], -) -with tempfile.NamedTemporaryFile(mode='r') as fp: - proc = subprocess.run(['gcc', '-E', '-o', fp.name, '-DPY_CFFI=1', - '../src/mrmailbox.h']) - proc.check_returncode() - ffibuilder.cdef(fp.read()) +def ffibuilder(): + builder = cffi.FFI() + builder.set_source( + 'deltachat.capi', + """ + #include + """, + libraries=['deltachat'], + ) + builder.cdef(""" + typedef int... time_t; + """) + cc = distutils.ccompiler.new_compiler(force=True) + distutils.sysconfig.customize_compiler(cc) + with tempfile.NamedTemporaryFile(mode='w', suffix='.h') as src_fp: + src_fp.write('#include ') + src_fp.flush() + with tempfile.NamedTemporaryFile(mode='r') as dst_fp: + cc.preprocess(source=src_fp.name, + output_file=dst_fp.name, + macros=[('PY_CFFI', '1')]) + builder.cdef(dst_fp.read()) + return builder if __name__ == '__main__': - ffibuilder.compile(verbose=True) + builder = ffibuilder() + builder.compile(verbose=True) diff --git a/src/mrmailbox.h b/src/mrmailbox.h index 70d8c87f..c42ac497 100644 --- a/src/mrmailbox.h +++ b/src/mrmailbox.h @@ -150,18 +150,15 @@ extern "C" { #ifndef PY_CFFI #include #include /* defines uint16_t */ +#endif + #include "mrarray.h" -#endif #include "mrchatlist.h" -#ifndef PY_CFFI #include "mrchat.h" -#endif #include "mrmsg.h" #include "mrcontact.h" -#ifndef PY_CFFI #include "mrlot.h" #include "mrevent.h" -#endif /** diff --git a/src/mrmsg.h b/src/mrmsg.h index 58e2eb25..d2c6dde9 100644 --- a/src/mrmsg.h +++ b/src/mrmsg.h @@ -26,10 +26,6 @@ extern "C" { #endif -#ifdef PY_CFFI -typedef int... time_t; -#endif - typedef struct _mrmailbox mrmailbox_t;