Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Cameronsplaze opened this issue Feb 17, 2022 · 10 comments
Open

Comments

@Cameronsplaze
Copy link

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
Copy link
Member

bk138 commented Feb 18, 2022

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
Copy link
Author

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
Copy link
Author

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
Copy link
Member

bk138 commented Mar 14, 2022

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
Copy link
Author

Cameronsplaze commented Mar 14, 2022

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
Copy link
Member

bk138 commented Mar 15, 2022

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
Copy link
Author

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
Copy link
Member

bk138 commented Mar 18, 2022

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

@Cameronsplaze
Copy link
Author

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
Copy link
Member

bk138 commented Apr 2, 2022

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants