wlav / cppyy

Other
407 stars 42 forks source link

Can bindings be saved permanently and not just in temporary memory? #25

Closed danielcjacobs closed 2 years ago

danielcjacobs commented 2 years ago

All the uses I'm seeing for cppyy define the bindings as they need to be used (e.g. I want to use C++ MyClass in python, so in a single python script I will generate the python binding and use it).

Is it possible to generate more "permanent" bindings that can be used later?

For example, let's say I have a project containing classes A, B, and C. Is it possible to generate the bindings when my project is built, so that anyone using the project later can just do from cppyy.gbl import A and use the binding?

wlav commented 2 years ago

No, by design it can not. Furthermore, everything in Python is run-time anyway, so the only thing you could possibly hope to gain is a lesser run-time dependency (there is no performance benefit), but in that space, pybind11 is impossible to beat as it has no run-time dependency at all (at a cost of flexibility and performance), so that would be my recommendation there.

There is the issue of a simpler installation procedure, esp. on Windows where it's very difficult to setup the compiler environment, but if pyinstaller is used to also distributed the PCH, then that's all self-contained. I appreciate that this can be improved and better documented. :)

As the question of compiled v.s. run-time comes up regularly, I made a write-up here, explaining the reasons behind the designs: https://cppyy.readthedocs.io/en/latest/philosophy.html .

danielcjacobs commented 2 years ago

Awesome, thanks for the clear answer!