diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..1508fa9 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,9 @@ + +[build-system] +requires = [ + "setuptools>=42", + "wheel", + "pybind11>=2.9.1", +] + +build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index be1a9e1..c8e5313 100644 --- a/setup.py +++ b/setup.py @@ -1,46 +1,46 @@ import os import platform -from setuptools import setup, Extension +from glob import glob +from setuptools import setup from distutils.sysconfig import get_python_inc +from pybind11.setup_helpers import Pybind11Extension, build_ext +__version__ = "4.0.0" -# python include dir -py_include_dir = os.path.join(get_python_inc()) -# cpp flags -cpp_args = ['-std=c++17'] -# include directories -include_dirs = [py_include_dir, './pybind11/include', './SEAL/native/src', './SEAL/build/native/src'] -# library path -extra_objects = ['./SEAL/build/lib/libseal-4.0.a'] -# available wrapper: src/wrapper.cpp, src/wrapper_with_pickle.cpp -wrapper_file = 'src/wrapper.cpp' +include_dirs = [get_python_inc(), 'pybind11/include', 'SEAL/native/src', 'SEAL/build/native/src'] -if platform.system() == "Windows": - cpp_args[0] = '/std:c++latest' # /std:c++1z - extra_objects[0] = './SEAL/build/lib/seal-4.0.lib' +extra_objects = sorted(glob('SEAL/build/lib/*.lib') if platform.system() == "Windows" else glob('SEAL/build/lib/*.a')) -if not os.path.exists(extra_objects[0]): - print('Not found the seal lib file') +cpp_args = ['/std:c++latest'] if platform.system() == "Windows" else ['-std=c++17'] + +if len(extra_objects) < 1 or not os.path.exists(extra_objects[0]): + print('Not found the seal lib file, check the `SEAL/build/lib`') exit(0) +elif len(extra_objects) > 1: + print('Exists unknown extra objects, may cause exception') ext_modules = [ - Extension( - name='seal', - sources=[wrapper_file], + Pybind11Extension( + "seal", + sorted(glob('src/*.cpp')), include_dirs=include_dirs, - language='c++', extra_compile_args=cpp_args, extra_objects=extra_objects, + define_macros = [('VERSION_INFO', __version__)], ), ] setup( - name='seal', - version='4.0', - author='Huelse', - author_email='huelse@oini.top', - description='Python wrapper for the Microsoft SEAL', - url='https://github.com/Huelse/SEAL-Python', - license='MIT', + name="seal", + version=__version__, + author="Huelse", + author_email="topmaxz@protonmail.com", + url="https://github.com/Huelse/SEAL-Python", + description="Python wrapper for the Microsoft SEAL", + long_description="", ext_modules=ext_modules, + cmdclass={"build_ext": build_ext}, + zip_safe=False, + license='MIT', + python_requires=">=3.6", ) diff --git a/src/wrapper.cpp b/src/wrapper.cpp index 45322d3..c3671a1 100644 --- a/src/wrapper.cpp +++ b/src/wrapper.cpp @@ -13,7 +13,8 @@ PYBIND11_MAKE_OPAQUE(std::vector); PYBIND11_MODULE(seal, m) { - m.doc() = "Microsoft SEAL (4.0) for Python, from https://github.com/Huelse/SEAL-Python"; + m.doc() = "Microsoft SEAL for Python, from https://github.com/Huelse/SEAL-Python"; + m.attr("__version__") = "4.0.0"; py::bind_vector>(m, "VectorDouble", py::buffer_protocol()); py::bind_vector>(m, "VectorInt", py::buffer_protocol());