From bfe752433f2c7493128996317140138bd4d385f2 Mon Sep 17 00:00:00 2001 From: Dantali0n Date: Wed, 17 Sep 2025 20:03:28 +0200 Subject: [PATCH] Fixes #30, Add CMake steps to install python bindings (#31) --- python/CMakeLists.txt | 13 +++++++++++++ python/__init__.py | 16 ++++++++++++++++ python/bindings.cpp | 6 ++++-- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 python/__init__.py diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 0df8767..77968ec 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -8,5 +8,18 @@ if(NOT pybind11_FOUND) FetchContent_MakeAvailable(pybind11) endif() +# Needed to set ${Python_VERSION_MAJOR} and ${Python_VERSION_MINOR} +find_package( + Python REQUIRED +) + pybind11_add_module(pytrigdx bindings.cpp) target_link_libraries(pytrigdx PRIVATE trigdx) +set_target_properties(pytrigdx PROPERTIES OUTPUT_NAME "trigdx") + +set(PYTHON_SITE_PACKAGES + "${CMAKE_INSTALL_LIBDIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/trigdx" +) + +install(TARGETS pytrigdx DESTINATION ${PYTHON_SITE_PACKAGES}) +install(FILES __init__.py DESTINATION ${PYTHON_SITE_PACKAGES}) diff --git a/python/__init__.py b/python/__init__.py new file mode 100644 index 0000000..d7d467b --- /dev/null +++ b/python/__init__.py @@ -0,0 +1,16 @@ +from .trigdx import Reference, Lookup16K, Lookup32K, LookupAVX16K, LookupAVX32K + +try: + from .trigdx import MKL +except ImportError: + pass + +try: + from .trigdx import GPU +except ImportError: + pass + +try: + from .trigdx import LookupXSIMD16K, LookupXSIMD32K +except ImportError: + pass diff --git a/python/bindings.cpp b/python/bindings.cpp index c8153df..8f2b4d7 100644 --- a/python/bindings.cpp +++ b/python/bindings.cpp @@ -72,7 +72,9 @@ void bind_backend(py::module &m, const char *name) { .def("compute_sincosf", &compute_sincos); } -PYBIND11_MODULE(pytrigdx, m) { +PYBIND11_MODULE(trigdx, m) { + m.doc() = "TrigDx python bindings"; + py::class_>(m, "Backend") .def("init", &Backend::init); @@ -91,4 +93,4 @@ PYBIND11_MODULE(pytrigdx, m) { bind_backend>(m, "LookupXSIMD16K"); bind_backend>(m, "LookupXSIMD32K"); #endif -} \ No newline at end of file +}