add xl ocaml bindings
PATCH 1/1 add xl ocaml bindings
--- tools/ocaml/Makefile | 2 +- tools/ocaml/common.make | 2 +- tools/ocaml/libs/xl/xl.ml | 209 ++++++++++++ tools/ocaml/libs/xl/xl.mli | 209 ++++++++++++ tools/ocaml/libs/xl/xl_stubs.c | 706 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1126 insertions(+), 2 deletions(-) create mode 100644 tools/ocaml/libs/xl/xl.ml create mode 100644 tools/ocaml/libs/xl/xl.mli create mode 100644 tools/ocaml/libs/xl/xl_stubs.c
tools/ocaml/Makefile +1 -1
@@ -4,7 +4,7 @@ include $(XEN_ROOT)/tools/Rules.mk SUBDIRS_LIBS = \ libs/uuid libs/mmap \ libs/log libs/xc libs/eventchn \ - libs/xb libs/xs + libs/xb libs/xs libs/xl SUBDIRS_PROGRAMS = xenstored
tools/ocaml/common.make +1 -1
@@ -9,7 +9,7 @@ OCAMLLEX ?= ocamllex OCAMLYACC ?= ocamlyacc CFLAGS += -fPIC -Werror -CFLAGS += -I$(TOPLEVEL)/../include -I$(TOPLEVEL)/../libxc +CFLAGS += -I$(TOPLEVEL)/../include -I$(TOPLEVEL)/../libxc -I$(TOPLEVEL)/../xenstore -I$(TOPLEVEL)/../libxl CFLAGS-$(CONFIG_Linux) += -I/usr/lib64/ocaml -I/usr/lib/ocaml CFLAGS-$(CONFIG_NetBSD) += -I/usr/pkg/lib/ocaml -fPIC
tools/ocaml/libs/xl/xl.ml new file +209 -0
209 lines not on this page · raw message
tools/ocaml/libs/xl/xl.mli new file +209 -0
209 lines not on this page · raw message
tools/ocaml/libs/xl/xl_stubs.c new file +706 -0
706 lines not on this page · raw message
Signature · 1 line
1.7.1
Not really a comment on this patch as such but more a related thought... How many language bindings do we think there are going to be and how much effort do we expect it would be keeping them all (or even just the interesting subset) up to date?
Is it worth investing the time up front to define a (simple) IDL and to generate the C header and language bindings from that?
Are there any existing IDLs which would meet our needs?
Another thought is that an IDL would partially isolate people changing the libxl interface from needing to know enough about each language to fixup the bindings (or else they may break the build). At least in the normal case where the change does not require a change to the IDL then a simple regeneration should be enough to update the bindings for the change.
On the other hand sometimes maintaining the auto code generator can be more work than just maintaining bindings by hand...
Ian.
Quoted 5 lines · Ian Campbell
Not really a comment on this patch as such but more a related thought... How many language bindings do we think there are going to be and how much effort do we expect it would be keeping them all (or even just the interesting subset) up to date?
I'm not sure if you're asking generally in terms of languages or in terms of bindings. I think from the point of view of bindings, that was the only thing left that required a binding. in terms of language, I don't really know if anyone is going to add some python bindings or not. it depends if xend is going to die, or is going to be ported.
effort wise, it's hard to answer since it depends on lots of variables. for example, API stability of libxenlight.
Quoted 5 lines
Is it worth investing the time up front to define a (simple) IDL and to generate the C header and language bindings from that?
Are there any existing IDLs which would meet our needs?
Theoretically, yes. pratically there's no IDL that i know of, that generate anything remotely close to be good or even useful. (it's maybe no surprise that all the python bindings are not autogenerated either)
swig seems to generate bindings really close to the C layer which make it quite annoying since the ml glue code become quick thick and quite annoying to write (converting back and forth types) and i've never actually tested the output of swig, and last time i tried camlIDL on a simple example, it generated a code that would segfault.
one more thing about generic bindings generator, is that it's hard to provide nice and clean interfaces. most of the time you stay really close to the C layer, which defeat the whole point of using a high level language for the user.
FYI, I've rewritten a little program to help me generate the bindings actually, but yet, it's quite painful to get right (and it's not in any Xen-friendly language either), and in the end i decided to take some of the output and fix it up by hand. in any case, it's really really far from having a automatic "./program idl > code" step in the code.
Quoted 6 lines
the libxl interface from needing to know enough about each language to fixup the bindings (or else they may break the build). At least in the normal case where the change does not require a change to the IDL then a simple regeneration should be enough to update the bindings for the change.
hopefully in most cases, as long as everything doesn't change too badly, adding fields is relatively easy even for someone that doesn't know ocaml.
Signature · 1 line
Vincent
Hello Ian,
Am Montag, den 28.06.2010, 10:59 +0100 schrieb Ian Campbell:
Quoted 17 lines
Not really a comment on this patch as such but more a related thought... How many language bindings do we think there are going to be and how much effort do we expect it would be keeping them all (or even just the interesting subset) up to date?
Is it worth investing the time up front to define a (simple) IDL and to generate the C header and language bindings from that?
Are there any existing IDLs which would meet our needs?
Another thought is that an IDL would partially isolate people changing the libxl interface from needing to know enough about each language to fixup the bindings (or else they may break the build). At least in the normal case where the change does not require a change to the IDL then a simple regeneration should be enough to update the bindings for the change.
Quoted 4 lines
On the other hand sometimes maintaining the auto code generator can be more work than just maintaining bindings by hand...
Ian.
maybe http://www.swig.org/ might help in this case.
It supports ocaml, python and also many more targets (like perl which i would love to get :) )...
According to http://www.swig.org/tutorial.html it looks like it could save the effort of maintaining the bindings one by one in parallel...
Marc
Quoted 9 lines · Zhigang Wang
I did some investigation on python bindings. It seems the best way today is using ctypes.
There are a few tools to autogenerate the bindings, but in my mind, the best way
is: generate at first time and then make some changes and maintain it manually. I think user readability is most important.And I was thinking xl should written in python.
We already have a toolstack written in python: xend.
I think that rather than rewriting xl in python, it would be much better to port xend to libxl.
Re: [PATCH] add xl ocaml bindings [and 1 more messages]
In reply to Ian CampbellIan Campbell writes ("Re: [Xen-devel] [PATCH] add xl ocaml bindings"):
Quoted 2 lines
Is it worth investing the time up front to define a (simple) IDL and to generate the C header and language bindings from that?
I think so but this is not a trivial problem, and we shouldn't block new language bindings on the availability of an IDL compiler.
Quoted 1 line
Are there any existing IDLs which would meet our needs?
We've had a look, but unfortunately there aren't really.
Marc - A. Dahlhaus writes ("Re: [Xen-devel] [PATCH] add xl ocaml bindings"):
Quoted 1 line
maybe http://www.swig.org/ might help in this case.
Urgh. Swig takes a pretty unpleasant approach. I've been involved in other projects which used it and it was more trouble than it was worth.
Ian.
Vincent Hanquez writes ("[Xen-devel] [PATCH] add xl ocaml bindings"):
Quoted 1 line
Signed-off-by Vincent Hanquez <[email protected]>
On my machine this breaks the build ("make -j4 KERNELS=''" with everything relevant in ccache so the C parts of the build are very fast):
=== building libs/xl
make[4]: *** No targets specified and no makefile found. Stop. make[3]: *** [SUBDIRS_LIBS] Error 2
make[3]: Leaving directory `/u/iwj/work/xen-unstable-tools.hg/tools/ocaml' make[2]: *** [subdir-install-ocaml] Error 2
make[2]: Leaving directory `/u/iwj/work/xen-unstable-tools.hg/tools' make[1]: *** [subdirs-install] Error 2
make[1]: Leaving directory `/u/iwj/work/xen-unstable-tools.hg/tools'
make: *** [install-tools] Error 2
make: *** Waiting for unfinished jobs....
Ian.
PATCH 1/1 missing makefile for libxl
--- tools/ocaml/libs/xl/Makefile | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) create mode 100644 tools/ocaml/libs/xl/Makefile
tools/ocaml/libs/xl/Makefile new file +26 -0
@@ -0,0 +1,26 @@ +TOPLEVEL=../.. +XEN_ROOT=$(TOPLEVEL)/../.. +include $(TOPLEVEL)/common.make + +OBJS = xl +INTF = xl.cmi +LIBS = xl.cma xl.cmxa + +xl_OBJS = $(OBJS) +xl_C_OBJS = xl_stubs + +OCAML_LIBRARY = xl + +all: $(INTF) $(LIBS) + +libs: $(LIBS) + +.PHONY: install +install: $(LIBS) META + ocamlfind install -destdir $(DESTDIR)$(shell ocamlfind printconf destdir) -ldconf ignore xl META $(INTF) $(LIBS) *.a *.so *.cmx + +.PHONY: uninstall +uninstall: + ocamlfind remove xl + +include $(TOPLEVEL)/Makefile.rules
Signature · 1 line
1.7.1
I did some investigation on python bindings. It seems the best way today is using ctypes.
There are a few tools to autogenerate the bindings, but in my mind, the best way
is: generate at first time and then make some changes and maintain it manually. I think user readability is most important.
And I was thinking xl should written in python.
Thanks,
Zhigang
Quoted 50 lines · Vincent Hanquez
Quoted 5 lines · Ian Campbell
Not really a comment on this patch as such but more a related thought... How many language bindings do we think there are going to be and how much effort do we expect it would be keeping them all (or even just the interesting subset) up to date?
I'm not sure if you're asking generally in terms of languages or in terms of bindings. I think from the point of view of bindings, that was the only thing left that required a binding. in terms of language, I don't really know if anyone is going to add some python bindings or not. it depends if xend is going to die, or is going to be ported.
effort wise, it's hard to answer since it depends on lots of variables. for example, API stability of libxenlight.
Quoted 5 lines
Is it worth investing the time up front to define a (simple) IDL and to generate the C header and language bindings from that?
Are there any existing IDLs which would meet our needs?
Theoretically, yes. pratically there's no IDL that i know of, that generate anything remotely close to be good or even useful. (it's maybe no surprise that all the python bindings are not autogenerated either)
swig seems to generate bindings really close to the C layer which make it quite annoying since the ml glue code become quick thick and quite annoying to write (converting back and forth types) and i've never actually tested the output of swig, and last time i tried camlIDL on a simple example, it generated a code that would segfault.
one more thing about generic bindings generator, is that it's hard to provide nice and clean interfaces. most of the time you stay really close to the C layer, which defeat the whole point of using a high level language for the user.
FYI, I've rewritten a little program to help me generate the bindings actually, but yet, it's quite painful to get right (and it's not in any Xen-friendly language either), and in the end i decided to take some of the output and fix it up by hand. in any case, it's really really far from having a automatic "./program idl > code" step in the code.
Quoted 6 lines
the libxl interface from needing to know enough about each language to fixup the bindings (or else they may break the build). At least in the normal case where the change does not require a change to the IDL then a simple regeneration should be enough to update the bindings for the change.
hopefully in most cases, as long as everything doesn't change too badly, adding fields is relatively easy even for someone that doesn't know ocaml.