From b1261ed0287227f805cf1888518975becf13e3c6 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Sat, 30 Dec 2017 12:53:58 +0100 Subject: [PATCH] WIP: First stop towards python bindings This is a very rough first stab at compiling CFFI Python bindings for deltachat-core. --- python/setup.py | 22 ++++++++++++++++++++++ python/src/deltachat/_build.py | 23 +++++++++++++++++++++++ src/mrmailbox.h | 6 ++++++ src/mrmsg.h | 4 ++++ 4 files changed, 55 insertions(+) create mode 100644 python/setup.py create mode 100644 python/src/deltachat/_build.py diff --git a/python/setup.py b/python/setup.py new file mode 100644 index 00000000..3e834d45 --- /dev/null +++ b/python/setup.py @@ -0,0 +1,22 @@ +import setuptools + + +setuptools.setup( + name='deltachat', + version='0.1', + description='Python bindings for deltachat-core using CFFI', + author='Delta Chat contributors', + setup_requires=['cffi>=1.0.0'], + install_requires=['cffi>=1.0.0'], + packages=setuptools.find_packages('src'), + package_dir={'': 'src'}, + cffi_modules=['src/deltachat/_build.py:ffibuilder'], + classifiers=[ + 'Development Status :: 3 - Alpha', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: GNU General Public License (GPL)', + 'Programming Language :: Python :: 3', + 'Topic :: Communications :: Email', + 'Topic :: Software Development :: Libraries', + ], +) diff --git a/python/src/deltachat/_build.py b/python/src/deltachat/_build.py new file mode 100644 index 00000000..65d00ce1 --- /dev/null +++ b/python/src/deltachat/_build.py @@ -0,0 +1,23 @@ +import subprocess +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()) + + +if __name__ == '__main__': + ffibuilder.compile(verbose=True) diff --git a/src/mrmailbox.h b/src/mrmailbox.h index 10d55bdc..70d8c87f 100644 --- a/src/mrmailbox.h +++ b/src/mrmailbox.h @@ -147,15 +147,21 @@ extern "C" { */ +#ifndef PY_CFFI #include #include /* defines uint16_t */ #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 d2c6dde9..58e2eb25 100644 --- a/src/mrmsg.h +++ b/src/mrmsg.h @@ -26,6 +26,10 @@ extern "C" { #endif +#ifdef PY_CFFI +typedef int... time_t; +#endif + typedef struct _mrmailbox mrmailbox_t;