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;