[opam-devel] [MirageOS-devel] Cross-compiling OCaml, Mirage OS for rumprun, OPAM integration

Thomas Gazagnaire thomas at gazagnaire.org
Tue May 19 12:49:43 BST 2015


Hi Martin,

> My work in progress OPAM repository is here:
> 
> https://github.com/mato/opam-rumprun
> 
> This is enough to get an OCaml "Hello, World" running on rumprun, and I've
> also tested that the Unix package works as expected. So far so good.

That's really great! Looking forward to use MirageOS on bare metal :p

> However, in order to get Mirage to compile, I need to cross-compile Lwt and
> that does not work as expected:
> 
>    $ OCAMLFIND_TOOLCHAIN=rumprun ocaml setup.ml -configure --prefix /home/mato/.opam/system/x86_64-rumprun-netbsd/ --disable-libev
> 
> Results in:
> 
>    not checking for pkg-config
>    not checking for libev
>    testing for pthread: ........................... unavailable
>    not checking for glib
> 
>    The following recquired C libraries are missing: pthread.
> 
> The reason this happens is that discover.ml is invoking the following
> compile command:
> 
> /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
> 
> Note the inclusion of -I/usr/include -- this is presumably there so that
> the system OCaml compiler's headers are available, however it results in a
> conflict between the NetBSD headers provided by rumprun and the system
> headers.
> 
> What can be done to fix the above? Should I be using a host compiler built
> and installed by OPAM rather than the system compiler (4.02.1-1ppa3~precise
> on Debian wheezy). [I'll try this and see if it helps...]

Lwt's discover.ml is unfortunately known to be very ad hoc and often breaks so I am not very surprised. Usually patches to fix it sent upstream are kindly accepted (until someone be brave enough to completely rewrite that file). In the meantime, maybe passing `-use-pthread false` to discover.ml using `./configure --disable-pthread` could help.

> I tried to hack around the problem by using --enable-android-target, that
> causes discover.ml to succeed and the build then proceeds, failing on a
> different problem:
> 
> E: Failure("Expected built file '_build/src/unix/dlllwt-unix_stubs.so' doesn't exist.")
> 
> This is expected; the rumprun toolchain does not support dynamic linking
> and I have configured the ocaml-rumprun compiler with -no-shared-libs. Is
> there some way to tell OASIS to not expect any shared libraries to be
> built?

This is tricky, it requires a mix of ocamlbuild, oasis and oasis hackery. I found http://komar.bitcheese.net/en/howto_link_c_lib_statically_with_ocaml_app which might help.

> 
> General questions:
> 
> 1) Is this the right strategy for building an OCaml cross-compiler and
> integrating with OPAM?
> 
> AFAICS there are multiple approaches being used in the wild and OCaml
> upstream *claims* to include support for cross-compiling via -host and
> -target, however that support is not actually functional?

Where did you see these options? I've seen commits in OCaml trunk to have a better support for cross compilation, not totally sure what it the status of it though. Also, Andy Ray (in /cc) also started a similar effort to cross-compile ocaml to FPGA. I really hope all of this would converge, and that we can add the proper support for it in opam at one pont.

Sorry to not be able to help much, but I think the topic is quite important one but very hard as it will need to be address problems in in the whole toolchain: ocaml, ocamlfind, ocamlbuild, oasis, opam, ... 

> 2) Is there an easy way to switch ocamlc and the various other parts of the
> build system(s) involved into a verbose mode so that I can see what
> compilers are being invoked and why they fail? At the moment I'm using
> `strace' for this :-/

Unfortunately the tools have all separate option for this:

ocamlfind -verbose
ocamlbuild -classic-display
opam <command> -verbose

You can control opam verbosity via an environment variable but I don't think it's possible for the other tools.

Best,
Thomas

> 
> All ideas and help much appreciated,
> 
> Cheers,
> 
> Martin
> 
> [1] http://wiki.rumpkernel.org/Repo%3A-rumprun
> [2] https://github.com/whitequark/opam-android
> 
> _______________________________________________
> MirageOS-devel mailing list
> MirageOS-devel at lists.xenproject.org
> http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel



More information about the opam-devel mailing list