python: use pkg-config for system install

This commit is contained in:
Robert Schütz
2021-08-04 16:18:43 +02:00
committed by Floris Bruynooghe
parent 9cc2fd555f
commit 43e3f8f08b
4 changed files with 19 additions and 23 deletions

View File

@@ -25,6 +25,7 @@
- Speed up message receiving via IMAP a bit #3225 - Speed up message receiving via IMAP a bit #3225
- mark messages as seen on IMAP in batches #3223 - mark messages as seen on IMAP in batches #3223
- remove Received: based draft detection heuristic #3230 - remove Received: based draft detection heuristic #3230
- Use pkgconfig for building Python package #2590
## 1.77.0 ## 1.77.0

View File

@@ -1,5 +1,5 @@
[build-system] [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" build-backend = "setuptools.build_meta"
[tool.setuptools_scm] [tool.setuptools_scm]

View File

@@ -12,7 +12,10 @@ def main():
long_description=long_description, long_description=long_description,
author='holger krekel, Floris Bruynooghe, Bjoern Petersen and contributors', author='holger krekel, Floris Bruynooghe, Bjoern Petersen and contributors',
install_requires=['cffi>=1.0.0', 'pluggy', 'imapclient', 'requests'], 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'), packages=setuptools.find_packages('src'),
package_dir={'': 'src'}, package_dir={'': 'src'},
cffi_modules=['src/deltachat/_build.py:ffibuilder'], cffi_modules=['src/deltachat/_build.py:ffibuilder'],

View File

@@ -8,9 +8,9 @@ import shutil
import subprocess import subprocess
import tempfile import tempfile
import textwrap import textwrap
import types
import cffi import cffi
import pkgconfig # type: ignore
def local_build_flags(projdir, target): 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 projdir: The root directory of the deltachat-core-rust project.
:param target: The rust build target, `debug` or `release`. :param target: The rust build target, `debug` or `release`.
""" """
flags = types.SimpleNamespace() flags = {}
if platform.system() == 'Darwin': if platform.system() == 'Darwin':
flags.libs = ['resolv', 'dl'] flags['libraries'] = ['resolv', 'dl']
flags.extra_link_args = [ flags['extra_link_args'] = [
'-framework', 'CoreFoundation', '-framework', 'CoreFoundation',
'-framework', 'CoreServices', '-framework', 'CoreServices',
'-framework', 'Security', '-framework', 'Security',
] ]
elif platform.system() == 'Linux': elif platform.system() == 'Linux':
flags.libs = ['rt', 'dl', 'm'] flags['libraries'] = ['rt', 'dl', 'm']
flags.extra_link_args = [] flags['extra_link_args'] = []
else: else:
raise NotImplementedError("Compilation not supported yet on Windows, can you help?") raise NotImplementedError("Compilation not supported yet on Windows, can you help?")
target_dir = os.environ.get("CARGO_TARGET_DIR") target_dir = os.environ.get("CARGO_TARGET_DIR")
if target_dir is None: if target_dir is None:
target_dir = os.path.join(projdir, 'target') target_dir = os.path.join(projdir, 'target')
flags.objs = [os.path.join(target_dir, target, 'libdeltachat.a')] flags['extra_objects'] = [os.path.join(target_dir, target, 'libdeltachat.a')]
assert os.path.exists(flags.objs[0]), flags.objs assert os.path.exists(flags['extra_objects'][0]), flags['extra_objects']
flags.incs = [os.path.join(projdir, 'deltachat-ffi')] flags['include_dirs'] = [os.path.join(projdir, 'deltachat-ffi')]
return flags return flags
def system_build_flags(): def system_build_flags():
"""Construct build flags for building against an installed libdeltachat.""" """Construct build flags for building against an installed libdeltachat."""
flags = types.SimpleNamespace() return pkgconfig.parse('deltachat')
flags.libs = ['deltachat']
flags.objs = []
flags.incs = []
flags.extra_link_args = []
return flags
def extract_functions(flags): def extract_functions(flags):
@@ -69,7 +64,7 @@ def extract_functions(flags):
src_fp.write('#include <deltachat.h>') src_fp.write('#include <deltachat.h>')
cc.preprocess(source=src_name, cc.preprocess(source=src_name,
output_file=dst_name, output_file=dst_name,
include_dirs=flags.incs, include_dirs=flags['include_dirs'],
macros=[('PY_CFFI', '1')]) macros=[('PY_CFFI', '1')])
with open(dst_name, "r") as dst_fp: with open(dst_name, "r") as dst_fp:
return dst_fp.read() return dst_fp.read()
@@ -105,7 +100,7 @@ def find_header(flags):
try: try:
os.chdir(tmpdir) os.chdir(tmpdir)
cc.compile(sources=["where.c"], cc.compile(sources=["where.c"],
include_dirs=flags.incs, include_dirs=flags['include_dirs'],
macros=[("PY_CFFI_INC", "1")]) macros=[("PY_CFFI_INC", "1")])
finally: finally:
os.chdir(cwd) os.chdir(cwd)
@@ -183,10 +178,7 @@ def ffibuilder():
return DC_EVENT_DATA2_IS_STRING(e); return DC_EVENT_DATA2_IS_STRING(e);
} }
""", """,
include_dirs=flags.incs, **flags,
libraries=flags.libs,
extra_objects=flags.objs,
extra_link_args=flags.extra_link_args,
) )
builder.cdef(""" builder.cdef("""
typedef int... time_t; typedef int... time_t;