| 1 |
import os |
| 2 |
import sys |
| 3 |
|
| 4 |
import cffi |
| 5 |
|
| 6 |
MBD_H = 'src/mbd.h' |
| 7 |
LIBMBD_PREFIX = os.environ.get('LIBMBD_PREFIX') |
| 8 |
|
| 9 |
if LIBMBD_PREFIX == '': |
| 10 |
sys.exit() |
| 11 |
|
| 12 |
# some Conda environments do not add their include dir into default includes |
| 13 |
CONDA_PREFIX = os.environ.get('CONDA_PREFIX') |
| 14 |
if not LIBMBD_PREFIX and CONDA_PREFIX: |
| 15 |
LIBMBD_PREFIX = CONDA_PREFIX |
| 16 |
|
| 17 |
if LIBMBD_PREFIX: |
| 18 |
ext_kwargs = { |
| 19 |
'include_dirs': [f'{LIBMBD_PREFIX}/include'], |
| 20 |
'library_dirs': [f'{LIBMBD_PREFIX}/lib'], |
| 21 |
'runtime_library_dirs': [f'{LIBMBD_PREFIX}/lib'], |
| 22 |
} |
| 23 |
else: |
| 24 |
ext_kwargs = {} |
| 25 |
ffibuilder = cffi.FFI() |
| 26 |
ffibuilder.set_source( |
| 27 |
'pymbd._libmbd', '#include "mbd/mbd.h"', libraries=['mbd'], **ext_kwargs |
| 28 |
) |
| 29 |
with open(MBD_H) as f: |
| 30 |
ffibuilder.cdef(f.read()) |
| 31 |
|
| 32 |
if __name__ == '__main__': |
| 33 |
from cffi.setuptools_ext import cffi_modules |
| 34 |
from setuptools import Distribution |
| 35 |
|
| 36 |
if sys.platform[:6] == 'darwin': |
| 37 |
from distutils.unixccompiler import UnixCCompiler |
| 38 |
|
| 39 |
UnixCCompiler.runtime_library_dir_option = lambda self, dir: ['-rpath', dir] |
| 40 |
|
| 41 |
distribution = Distribution({'package_dir': {'': 'src'}}) |
| 42 |
cffi_modules(distribution, 'cffi_modules', ['cffi_build.py:ffibuilder']) |
| 43 |
cmd = distribution.cmdclass['build_ext'](distribution) |
| 44 |
cmd.inplace = 1 |
| 45 |
cmd.ensure_finalized() |
| 46 |
cmd.run() |