python-snap7 icon indicating copy to clipboard operation
python-snap7 copied to clipboard

switch to CFFI

Open gijzelaerr opened this issue 4 years ago • 5 comments

CFFI is an easier method to create bindings.

It also simplifies the binary wheels creation process, greatly simplifying the installation procedure.

https://cffi.readthedocs.io/en/latest/

gijzelaerr avatar May 08 '20 08:05 gijzelaerr

Snap7 is written in C++ and not C, this may not work.

From the CFFI Goals:

" There is no C++ support. Sometimes, it is reasonable to write a C wrapper around the C++ code and then call this C API with CFFI. Otherwise, look at other projects. I would recommend cppyy, which has got some similarities (and also works efficiently on both CPython and PyPy)."

swamper123 avatar Oct 14 '21 07:10 swamper123

I tried out pybind11. I made a small demo and built packages for all platforms (except Windows) using cibuildwheel. You can find the packages here. There are difficulties with the tests, but I think they can be solved. If you find pybind11 suitable, we can try it for the version 2.0.

nikteliy avatar Nov 26 '21 13:11 nikteliy

cool, cool, what do you think yourself? do you find it more suitable than the normal ctypes layer?

gijzelaerr avatar Nov 28 '21 10:11 gijzelaerr

Pybind11 + cibuildwheel greatly simplifies packaging workflow. But it requires experience in C++. I have no such experience, so I don't know what pitfalls to expect.

nikteliy avatar Nov 29 '21 11:11 nikteliy

i had good experiences with CFFI, didn't try out pybind11+ yet, so not sure how they compare. I know it is a header-only solution.

We can also try to write a prototype for both with just 2 or 3 basic functions and see how they compare.

gijzelaerr avatar Nov 29 '21 11:11 gijzelaerr