Skip to content

Commit

Permalink
setup: fixed the issues with not including .h include files.
Browse files Browse the repository at this point in the history
  • Loading branch information
YoSTEALTH committed Apr 23, 2024
1 parent a0df320 commit acf9cfb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
48 changes: 22 additions & 26 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from os import cpu_count
from shutil import copy2, copytree, rmtree
from shutil import copy2, copytree
from os.path import join
from tempfile import mkdtemp
from tempfile import TemporaryDirectory
from subprocess import run as sub_process_run
from setuptools import setup
from setuptools.command.build_ext import build_ext
Expand All @@ -10,20 +10,6 @@
from Cython.Distutils import Extension


uring = 'uring-ffi'
tmpdir = mkdtemp()
threads = cpu_count()
lib = join(tmpdir, 'libs/liburing')
libsrc = join(lib, 'src')
libinc = join(libsrc, 'include')

# compiler options
Options.annotate = False
Options.fast_fail = True
Options.docstrings = True
Options.warning_errors = False


class BuildExt(build_ext):

def initialize_options(self):
Expand All @@ -41,22 +27,34 @@ def build_extensions(self):
'libs/liburing/Makefile.quiet'):
copy2(src, join(tmpdir, src))

# sub_process_run(['./configure', '--use-libc'], cwd=lib, capture_output=True, check=True)
sub_process_run(['./configure'], cwd=lib, capture_output=True, check=True)
sub_process_run(['make', f'--jobs={threads}'], cwd=lib, capture_output=True)
# note: just runs `configure` & `make`, does not `install`.
sub_process_run(['./configure'], cwd=lib, capture_output=False, check=True)
sub_process_run(['make', f'--jobs={threads}'], cwd=lib, capture_output=False)

# replace `include` placeholder files with actual content.
copytree(libinc, 'src/liburing/include', dirs_exist_ok=True)
# have to replace `include` in `build_lib` e.g.'build/lib.linux-x86_64-cpython-313'
# as well since installer copies over the files before `BuildExt` is called.
copytree(libinc, join(self.build_lib, 'liburing/include'), dirs_exist_ok=True)
super().build_extensions()


if __name__ == '__main__':
try:
# compiler options
Options.annotate = False
Options.fast_fail = True
Options.docstrings = True
Options.warning_errors = False

with TemporaryDirectory() as tmpdir:
lib = join(tmpdir, 'libs/liburing')
libsrc = join(lib, 'src')
libinc = join(libsrc, 'include')
threads = cpu_count()
extension = [Extension(name='liburing.*', # where the `.so` will be saved.
sources=['src/liburing/*.pyx'],
language='c',
libraries=[uring],
libraries=['uring-ffi'],
library_dirs=[libsrc],
include_dirs=[libinc],
# optimize & remove debug symbols + data.
Expand All @@ -65,9 +63,7 @@ def build_extensions(self):
setup(cmdclass={'build_ext': BuildExt},
ext_modules=cythonize(extension,
nthreads=threads,
compiler_directives={'embedsignature': True, # show `__doc__`
compiler_directives={'language_level': 3,
'embedsignature': True, # show `__doc__`
'boundscheck': False,
'wraparound': False,
'language_level': 3}))
finally:
rmtree(tmpdir)
'wraparound': False}))
2 changes: 1 addition & 1 deletion src/liburing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dynamic_import import importer


__version__ = '2024.4.22'
__version__ = '2024.4.23'


importer(exclude_dir=['lib', 'include'])
Expand Down

0 comments on commit acf9cfb

Please sign in to comment.