LibVNC / libvncserver

LibVNCServer/LibVNCClient are cross-platform C libraries that allow you to easily implement VNC server or client functionality in your program.
GNU General Public License v2.0
1.1k stars 482 forks source link

[Feature request] Add automatic python3 bindings for the library #502

Open Cameronsplaze opened 2 years ago

Cameronsplaze commented 2 years ago

If you'd like to put out an incentive for implementing this feature, you can do so at https://issuehunt.io/r/LibVNC/libvncserver

Is your feature request related to a problem? Please describe.

I would like to use a vnc library in python, and re-writing one from scratch seems overkill. There aren't great alternatives in that language.

Describe the solution you'd like

By creating automatic python bindings from this library, you cover two languages with one. Plus maybe lay ground work for more later on.

Describe alternatives you've considered

RealVNC is the only library with python bindings I can find, and is very expensive. Strict python libraries like vncdotool are for automating cli tasks, and don't have all the necessary features. Everything else I can find is either closed source and don't support python (TightVNC sdk), or has a small community behind it.

Additional context

If this library turns out to be the best route for my project, I'd be willing to take a stab at implementing this over my weekends, if it's something you're interested in.

bk138 commented 2 years ago

Yes, that would be valuable. Also, I think that once one FFI binding is in place, others might be easier to add. So go ahead!

Cameronsplaze commented 2 years ago

Just an update on this, I'll try to work on it soon at https://github.com/Coldtoe-Devs/libvncserver.

I was originally researching pybind11, but they require you to explicitly list every bind you want. (Which means you'd have to maintain a bind list going forward, and might forget to forward a feature to python).

Thankfully, looks like there's a couple projects built on top of pybind11 to use it automatically, listed here (binder, AutoWig, and robotpy-build). I'll need to research which might be the best one to use here.

Cameronsplaze commented 2 years ago

It seems like pybind11 requires c++11 to compile, so I'm not sure any of those packages built on top of it will work on a C library. I can get the farthest so far with robotpy-build. I through together a basic c++ library, and got the binds working on that. But when trying the same process here on a C lib, it won't compile.

I'll keep researching a work around just in case, but what are your thoughts on switching to C++ from C? It'd let you use unique_ptr and shared_ptr too I believe, and they're strongly recommended by all of the binding packages.

bk138 commented 2 years ago

I'd say introducing C++ makes things overly complicated as LibVNCServer is a C library and will never be a C++ one. Using C++ for Python bindings sounds like quite an addition of code for a single purpose and thus a lot of maintenance work, but I might be wrong...

Cameronsplaze commented 2 years ago

If we went the C++ route, I think you'd want an all or nothing deal anyways. If switching the whole project to c++ is out, I should choose a older package to generate bindings. Looks like cython and maybe boost support C.

There is a chance that these won't have automatic bindings like pybind does, and you'll have to maintain a list of exactly what methods to bind. Would that be a deal breaker? I'll still look for a way to do this regardless.

bk138 commented 2 years ago

It would always be better to go with less dependencies, but if C++ is needed for painless Python bindings and all the Python/C++ is a CMake Opt-In, it would be OK from my side. Can you sketch out the general approach and/or what a developer's workflow would be in generating bindings?

Cameronsplaze commented 2 years ago

Since there's no way to compile this library in c++, I've been learning SWIG, which can generate bindings for C libraries. The nice thing is too, if you get it working for one language like python, you get a bunch of languages almost for free through it.

I have a minimal example I've been playing with here: https://github.com/Coldtoe-Devs/TestingSWIG. It also has todo's I need to learn, before I'm ready to try adding it to a library this large. Whenever you have a chance, could you review it, and see if there's any blockers or concerns for using swig here? I put any I had in the readme, with whatever else I thought was important.

bk138 commented 2 years ago

SWIG sounds good, let me know once you have a working proof of concept.

Cameronsplaze commented 2 years ago

After some research, I think spice might work out better for my project than VNC, so I'm not sure I'll have the motivation to keep working on this feature sadly. Sorry about dropping it like this. If someone was to pick this up for ANY language bindings, I do strongly think they should give SWIG at least a look.

Would you rather keep this issue open for if someones interested down the line? Or just have them open up their own issue?

bk138 commented 2 years ago

No problem at all, it's your time and your project! We'll leave this issue open and see if there's interest from other parties. Thanks for your effort so far!