<div dir="ltr"><br><br><div class="gmail_quote">Le mar. 19 mai 2015 à 10:50, Martin Lucina <<a href="mailto:martin@lucina.net">martin@lucina.net</a>> a écrit :<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">[Re-sending with correct opam-devel address]<br>
<br>
Hi all,<br>
<br>
I'm working on getting OCaml and Mirage OS running on top of the rumprun<br>
unikernel stack[1].<br>
<br>
Rumprun provides a unikernel stack with a POSIXy (NetBSD-HEAD) userspace<br>
and can run on Xen, QEMU/KVM, bare metal and POSIX userspace.  The<br>
resulting Mirage + rumprun unikernel will thus be able to run on all of the<br>
platforms rumprun supports.<br>
<br>
The first step to get this working is building an OCaml cross compiler that<br>
uses the rumprun cross compiler as its backend for building C code and<br>
linking.<br>
<br>
I've researched the various cross-compilation options for OCaml and for now<br>
have based my code off the approach used by Peter Zotov in his<br>
`opam-android' repository[2].<br>
<br>
My work in progress OPAM repository is here:<br>
<br>
<a href="https://github.com/mato/opam-rumprun" target="_blank">https://github.com/mato/opam-rumprun</a><br>
<br>
This is enough to get an OCaml "Hello, World" running on rumprun, and I've<br>
also tested that the Unix package works as expected. So far so good.<br>
<br>
However, in order to get Mirage to compile, I need to cross-compile Lwt and<br>
that does not work as expected:<br>
<br>
    $ OCAMLFIND_TOOLCHAIN=rumprun ocaml <a href="http://setup.ml" target="_blank">setup.ml</a> -configure --prefix /home/mato/.opam/system/x86_64-rumprun-netbsd/ --disable-libev<br>
<br>
Results in:<br>
<br>
    not checking for pkg-config<br>
    not checking for libev<br>
    testing for pthread: ........................... unavailable<br>
    not checking for glib<br>
<br>
    The following recquired C libraries are missing: pthread.<br>
<br>
The reason this happens is that <a href="http://discover.ml" target="_blank">discover.ml</a> is invoking the following<br>
compile command:<br>
<br>
/home/mato/projects/rumpkernel/rumprun/app-tools/rumprun-xen-cc -fno-defer-pop -Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT -c -I/usr/include -o /tmp/lwt_stubf12ac7.o -I/home/mato/.opam/system/x86_64-rumprun-netbsd/lib/ocaml /tmp/lwt_stubf12ac7.c<br>
<br>
Note the inclusion of -I/usr/include -- this is presumably there so that<br>
the system OCaml compiler's headers are available, however it results in a<br>
conflict between the NetBSD headers provided by rumprun and the system<br>
headers.<br>
<br>
What can be done to fix the above? Should I be using a host compiler built<br>
and installed by OPAM rather than the system compiler (4.02.1-1ppa3~precise<br>
on Debian wheezy). [I'll try this and see if it helps...]<br>
<br>
I tried to hack around the problem by using --enable-android-target, that<br>
causes <a href="http://discover.ml" target="_blank">discover.ml</a> to succeed and the build then proceeds, failing on a<br>
different problem:<br>
<br>
E: Failure("Expected built file '_build/src/unix/dlllwt-unix_stubs.so' doesn't exist.")<br>
<br>
This is expected; the rumprun toolchain does not support dynamic linking<br>
and I have configured the ocaml-rumprun compiler with -no-shared-libs. Is<br>
there some way to tell OASIS to not expect any shared libraries to be<br>
built?<br></blockquote><div><br></div><div>I suppose it will require to patch src/oasis/OASISLibrary l201 to have ext_lib be an option rather than a string. OASIS can be forked and PR sent on github, feel free to send a PR about that.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
General questions:<br>
<br>
1) Is this the right strategy for building an OCaml cross-compiler and<br>
integrating with OPAM?<br>
<br>
AFAICS there are multiple approaches being used in the wild and OCaml<br>
upstream *claims* to include support for cross-compiling via -host and<br>
-target, however that support is not actually functional?<br>
<br>
For the rumprun support to be as user-friendly as possible, we need an easy<br>
way of switching the backend rumprun cross-compiler and linker used by<br>
ocaml when the user wants to switch platforms or architectures. The<br>
approach used by the android repository I based my work off implies either:<br>
<br>
a) the user would have to *reinstall* the cross compiler (specifying eg.<br>
RUMPRUN_CC in the environment) and all packages using native code whenever<br>
they want to switch the backend compiler.<br>
<br>
b) we would have to provide different opam packages of the compiler and<br>
native libraries (Lwt) for each platform/arch combination supported by<br>
rumprun. This is unmanageable.<br>
<br>
2) Is there an easy way to switch ocamlc and the various other parts of the<br>
build system(s) involved into a verbose mode so that I can see what<br>
compilers are being invoked and why they fail? At the moment I'm using<br>
`strace' for this :-/<br>
<br>
All ideas and help much appreciated,<br>
<br>
Cheers,<br>
<br>
Martin<br>
<br>
[1] <a href="http://wiki.rumpkernel.org/Repo%3A-rumprun" target="_blank">http://wiki.rumpkernel.org/Repo%3A-rumprun</a><br>
[2] <a href="https://github.com/whitequark/opam-android" target="_blank">https://github.com/whitequark/opam-android</a><br>
_______________________________________________<br>
opam-devel mailing list<br>
<a href="mailto:opam-devel@lists.ocaml.org" target="_blank">opam-devel@lists.ocaml.org</a><br>
<a href="http://lists.ocaml.org/listinfo/opam-devel" target="_blank">http://lists.ocaml.org/listinfo/opam-devel</a><br>
</blockquote></div></div>