1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-04 18:29:19 +02:00

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.
This commit is contained in:
Floris Bruynooghe 2018-01-04 23:10:40 +01:00
parent b1261ed028
commit 9048a2dbab
3 changed files with 29 additions and 24 deletions

View file

@ -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 <deltachat/mrmailbox.h>
""",
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 <deltachat/mrmailbox.h>
""",
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 <deltachat/mrmailbox.h>')
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)