-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Provide a shared library for C users #9325
Comments
huh? you want us to rewrite in c? |
btw, the official response here is that you can use the RESTFul interface for this kind of stuff. |
no build the library "-buildmode=c-shared" |
@lpgc have you tried this on our repo and it works? if so, how about making a make target and a readme on how to use it? |
I'll give it my best shot! and report back here... I need to do a little background on the full effects of this buildmode on the resulting shared object before I "ready, fire, aim" ... it may require a separate .so from the native golang one... Rgds
|
@lpgc thanks for running with this, a c library could be very useful for some folks. |
Happy to! - my motivation is somewhat selfish as I want to be able to call into the API from Java (via JNA or JNI) and would prefer to "avoid" doing this via REST if possible... but that is always an option to fallback on... |
@lpgc @TomSweeneyRedHat as far as I know, according to the documentation, it is impossible to create shared C lib out of functions which are using complex go structures as well as interfaces. Disclaimer: I am not the expert, I faced a similar problem myself. If you have more experience and now something more, please share. |
@jmguzik thanks - sounds like this may be the direction to go, I guess I will decide how much of the API I need and I will take it from there! I'll close this issue for now, and re-open if I go ahead and create a "simple" API binding that would be generally useful to others! |
@lpgc issue is closed, but if you are still interested in some kind of starting point I wrote something like this: |
@lpgc forgot to add: I tested it against podman 2.2.1 |
@jmguzik very much appreciated, thanks for this... I was planning to do something similar! seems like a reasonable approach to create an appropriate set of "C" compatible "wrappers" to the underlying Golang structures and APIs! Kudos my friend! |
@lpgc No problem.. it seemed interesting so I invested a while to see how it works (my background is C/C++). |
good to know cheers! |
Have you tried: |
also creates rest api wrapper for Java if you want |
yeah I dont want the REST API ... |
@matejvasek I understand Go bindings are not using REST API (according to instruction: https://github.com/containers/podman/blob/master/docs/tutorials/podman-go-bindings.md). This mechanism avoids using REST API, though it has some (unexplored) limitations. |
+1! |
I think I see where are you heading in future. Right now |
@matejvasek To be honest I do not quite get your response. |
My point is that |
I believe that @lpgc don't want to depend on rest api provided by some service, he probably need to wrap some other package than |
@matejvasek To be honest I am from community so I do not know internals of bindings so well.
It cleary suggests/implies bindings are more native. If it is not the case, maybe other functions are needed to be wrapped. I followed blog post and translated main.go to libpodc.go believing I am interacting with native interface. Another thing is Pull (and inner function) just may use http interface to download image, I do not know. |
According to article, podman service is a must be to get bindings working. So whatever @lpgc needs, he has to take this into consideration. |
One more comment: I think we want to eliminate this Podman REST <-> OurApp and replace it with this: Podman Unix Socket <-> OurApp, not get rid of REST completely. |
Totally more native if you use Golang. You can use swagger generated C: http://a.tmp.ninja/Sm3YxYj6N0l1.tar
I don't understand, |
@matejvasek I think you are missing one point. Golang has a feature called cgo which enables possibility to compile Go code into shared C lib. That way it acts the same as you are using Go.
If you do not see it usefull from Golang then you do not see it useful from C. Golang functionality is embed into shared C lib: |
Podman Unix Socket is not rest api. |
exactly @jmguzik my intent is to be able to call directly into podman (libpod) API from a language other than golang hence the need for a shared lib with C bindings ... |
The socket is serving HTTP requests. API is described here: https://docs.podman.io/en/latest/_static/api.html#operation/libpodImagesPull. |
You can invoke it as it was almost as it was TCP: |
But still this is IPC socket which is a way better than Http. There is a difference to fight for. |
@lpgc if you want it to be able to run standalone -- deamonless, then you probably will need to wrap stuff from |
I think you can access socket even with code generated by swagger. |
This may be tricky since functions there are too complex to use cgo mechanism. Anyway this whole thing was just an excercise for me, as topic seemed interesting. I still think it is much more beneficial to wrap Golang bindings using shared C lib, because as a user you do not need to design interface yourself and you have native bindings at almost zero cost (cost of wrapper). IPC unix socket is quick enough and running service is not a problem, as for native go programs interacting with podman it is also designed to be this way. Anyway REST in C++ and especially C is not better solution anyway due to need of exploring external libs. |
valid point you need to install at least |
I don't know how difficult that could be. With regard to java: |
You can export only basic simple types and structs. Lambdas and interfaces are no go. For this interface a (complicated?) wrapper would be needed in Go.
Topic from the beginning had C in name and I focused on C. I think from C/C++ perspective. This one should be discussed further with @lpgc as he wanted to take C lib further. |
Maybe I misunderstood:
This can be understood as: If b) is true then wrapping I initially assumed a). and by REST I mean libpod API no matter if it runs on unix socket or tcp socket. |
If you don't want to do rest API, then you would be better off looking at wrapping pkg/domain/infra/abi. This is the direct calls into libpod from Podman. No service required. Note that this interface is not stable and not locked down. Perhaps in the future we could. |
@rhatdan In regards to your anwser:
How to see this comment from @TomSweeneyRedHat:
To explain, the interface in the directory you provided is quite difficult to cgo it. Would you accept contributions that will make wrappers and allow to generate C shared libs without REST? These files should be in your repo to keep them up to date. If interface is not stable and has to be maintained outside of podman's realm, this would not make much sense. From my perspective it was just an exercise to use podman without the need of usage REST in C/C++ (which is a nightmare IMO). I found a leak in podman by the way, so I think it was a good exercise. It could be taken further as topic seems interesting, but I don't know if there is a real need. |
Sure we would love to work with the community on this, the difficulty is once we define the API we have to make keep it static/stable, which is what we have done with the Rest API. I am not sure if @mheon is ready to specify a stable API to libpod yet. |
Another approach of shielding would be providing wrapper like https://github.com/containers/podman-py but in C. |
@rhatdan That is why wrapper around functions should be made inside your realm. In subproject (like podman-py) or inside podman itself. Even if not stable, it could be provided as experimental and worked on. |
actually my original intent was for a C API calling directly into libpod and not a wrapper onto the REST API, which is My actual intent was to allow a language environment to provide (some of) the same function as libpod w/o having to deploy any other component other than the shared object itself as part of the application/service deployed. I know the difference is a subtle one and perhaps not clear as to the advantage of one over the other ... I guess another way to look at this is perhaps as a C API to the various OCI artifacts etc ... like the major verbs and entities ... |
/kind feature
in order to enable access to libpod APIs from languages other than golang, libpod.so should be built as a C shared library
The text was updated successfully, but these errors were encountered: