From 43e3f8f08b1a22d1934b9a91f9e94efc4ccd8d3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Wed, 4 Aug 2021 16:18:43 +0200 Subject: [PATCH] python: use pkg-config for system install --- CHANGELOG.md | 1 + python/pyproject.toml | 2 +- python/setup.py | 5 ++++- python/src/deltachat/_build.py | 34 +++++++++++++--------------------- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a22a8e9f..7d81d5f26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - Speed up message receiving via IMAP a bit #3225 - mark messages as seen on IMAP in batches #3223 - remove Received: based draft detection heuristic #3230 +- Use pkgconfig for building Python package #2590 ## 1.77.0 diff --git a/python/pyproject.toml b/python/pyproject.toml index 43528a024..a3e714f31 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=45", "wheel", "setuptools_scm>=6.2", "cffi>=1.0.0"] +requires = ["setuptools>=45", "wheel", "setuptools_scm>=6.2", "cffi>=1.0.0", "pkgconfig"] build-backend = "setuptools.build_meta" [tool.setuptools_scm] diff --git a/python/setup.py b/python/setup.py index 21b838bd4..728772d6d 100644 --- a/python/setup.py +++ b/python/setup.py @@ -12,7 +12,10 @@ def main(): long_description=long_description, author='holger krekel, Floris Bruynooghe, Bjoern Petersen and contributors', install_requires=['cffi>=1.0.0', 'pluggy', 'imapclient', 'requests'], - setup_requires=['setuptools_scm'], # required for compatibility with `python3 setup.py sdist` + setup_requires=[ + 'setuptools_scm', # required for compatibility with `python3 setup.py sdist` + 'pkgconfig', + ], packages=setuptools.find_packages('src'), package_dir={'': 'src'}, cffi_modules=['src/deltachat/_build.py:ffibuilder'], diff --git a/python/src/deltachat/_build.py b/python/src/deltachat/_build.py index e2ff57645..2e64d57d4 100644 --- a/python/src/deltachat/_build.py +++ b/python/src/deltachat/_build.py @@ -8,9 +8,9 @@ import shutil import subprocess import tempfile import textwrap -import types import cffi +import pkgconfig # type: ignore def local_build_flags(projdir, target): @@ -19,36 +19,31 @@ def local_build_flags(projdir, target): :param projdir: The root directory of the deltachat-core-rust project. :param target: The rust build target, `debug` or `release`. """ - flags = types.SimpleNamespace() + flags = {} if platform.system() == 'Darwin': - flags.libs = ['resolv', 'dl'] - flags.extra_link_args = [ + flags['libraries'] = ['resolv', 'dl'] + flags['extra_link_args'] = [ '-framework', 'CoreFoundation', '-framework', 'CoreServices', '-framework', 'Security', ] elif platform.system() == 'Linux': - flags.libs = ['rt', 'dl', 'm'] - flags.extra_link_args = [] + flags['libraries'] = ['rt', 'dl', 'm'] + flags['extra_link_args'] = [] else: raise NotImplementedError("Compilation not supported yet on Windows, can you help?") target_dir = os.environ.get("CARGO_TARGET_DIR") if target_dir is None: target_dir = os.path.join(projdir, 'target') - flags.objs = [os.path.join(target_dir, target, 'libdeltachat.a')] - assert os.path.exists(flags.objs[0]), flags.objs - flags.incs = [os.path.join(projdir, 'deltachat-ffi')] + flags['extra_objects'] = [os.path.join(target_dir, target, 'libdeltachat.a')] + assert os.path.exists(flags['extra_objects'][0]), flags['extra_objects'] + flags['include_dirs'] = [os.path.join(projdir, 'deltachat-ffi')] return flags def system_build_flags(): """Construct build flags for building against an installed libdeltachat.""" - flags = types.SimpleNamespace() - flags.libs = ['deltachat'] - flags.objs = [] - flags.incs = [] - flags.extra_link_args = [] - return flags + return pkgconfig.parse('deltachat') def extract_functions(flags): @@ -69,7 +64,7 @@ def extract_functions(flags): src_fp.write('#include ') cc.preprocess(source=src_name, output_file=dst_name, - include_dirs=flags.incs, + include_dirs=flags['include_dirs'], macros=[('PY_CFFI', '1')]) with open(dst_name, "r") as dst_fp: return dst_fp.read() @@ -105,7 +100,7 @@ def find_header(flags): try: os.chdir(tmpdir) cc.compile(sources=["where.c"], - include_dirs=flags.incs, + include_dirs=flags['include_dirs'], macros=[("PY_CFFI_INC", "1")]) finally: os.chdir(cwd) @@ -183,10 +178,7 @@ def ffibuilder(): return DC_EVENT_DATA2_IS_STRING(e); } """, - include_dirs=flags.incs, - libraries=flags.libs, - extra_objects=flags.objs, - extra_link_args=flags.extra_link_args, + **flags, ) builder.cdef(""" typedef int... time_t;