diff --git a/MANIFEST.in b/MANIFEST.in --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,3 +2,6 @@ include requirements*.txt include version.txt recursive-include swh py.typed +include swh/perfecthash.c +include swh/perfecthash.h +include perfecthash_build.py diff --git a/mypy.ini b/mypy.ini --- a/mypy.ini +++ b/mypy.ini @@ -19,3 +19,6 @@ [mypy-rados.*] ignore_missing_imports = True + +[mypy-_perfecthash_cffi.*] +ignore_missing_imports = True diff --git a/perfecthash_build.py b/perfecthash_build.py new file mode 100644 --- /dev/null +++ b/perfecthash_build.py @@ -0,0 +1,24 @@ +from cffi import FFI + +ffibuilder = FFI() + +# cdef() expects a single string declaring the C types, functions and +# globals needed to use the shared object. It must be in valid C syntax. +ffibuilder.cdef( + """ +int build(char* path); +""" +) + +ffibuilder.set_source( + "_perfecthash_cffi", + """ + #include "swh/perfecthash.h" + """, + sources=["swh/perfecthash.c"], + include_dirs=["."], + libraries=["cmph"], +) # library name, for the linker + +if __name__ == "__main__": + ffibuilder.compile(verbose=True) diff --git a/requirements.txt b/requirements.txt --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,8 @@ # should match https://pypi.python.org/pypi names. For the full spec or # dependency lines, see https://pip.readthedocs.org/en/1.1/requirements.html +cffi + # remote storage API server aiohttp >= 3 click diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -46,10 +46,11 @@ url="https://forge.softwareheritage.org/diffusion/DOBJS", packages=find_packages(), install_requires=parse_requirements() + parse_requirements("swh"), - setup_requires=["setuptools-scm"], + setup_requires=["setuptools-scm", "cffi"], use_scm_version=True, extras_require={"testing": parse_requirements("test")}, include_package_data=True, + cffi_modules=["perfecthash_build.py:ffibuilder"], entry_points=""" [swh.cli.subcommands] objstorage=swh.objstorage.cli diff --git a/swh/objstorage/tests/test_perfecthash.py b/swh/objstorage/tests/test_perfecthash.py new file mode 100644 --- /dev/null +++ b/swh/objstorage/tests/test_perfecthash.py @@ -0,0 +1,5 @@ +from _perfecthash_cffi import lib + + +def test_build(): + assert lib.build("path") == 0 diff --git a/swh/perfecthash.h b/swh/perfecthash.h new file mode 100644 --- /dev/null +++ b/swh/perfecthash.h @@ -0,0 +1 @@ +#include diff --git a/swh/perfecthash.c b/swh/perfecthash.c new file mode 100644 --- /dev/null +++ b/swh/perfecthash.c @@ -0,0 +1,5 @@ +#include "swh/perfecthash.h" + +int build(char *path) { + return 0; +}