[To be solved (hopefully)] Cross compiling project using jbuilder

Adding a package to one of the opam-cross-* repositories (I’m especially interested by https://github.com/whitequark/opam-cross-windows ) was super easy when all invocations to the compiler were going throw ocamlfind:

Thanks to a file ~/.opam/4.04.0/lib/findlib.conf.d/windows.conf defining

path(windows) = "/home/pirbo/.opam/4.04.0/windows-sysroot/lib"
destdir(windows) = "/home/pirbo/.opam/4.04.0/windows-sysroot/lib"
stdlib(windows) = "/home/pirbo/.opam/4.04.0/windows-sysroot/lib/ocaml"
ocamlc(windows) = "/home/pirbo/.opam/4.04.0/windows-sysroot/bin/ocamlc"
[...]

you were just adding env OCAMLFIND_TOOLCHAIN=windows before your make/ocamlbuild/… invocation and the library was cross-compiled!

But because Earth never stops turning, everybody now move to jbuilder. I naively tried env OCAMLFIND_TOOLCHAIN=windows jbuilder build -p biniou but of course

    ocamlopt bin/bdump.exe (exit 2)                      
(cd _build/default && /home/pirbo/.opam/4.04.0/bin/ocamlopt.opt -w -40 -g -o bin/bdump.exe -I /home/pirbo/.opam/4.04.0/windows-sysroot/lib/bytes -I /home/pirbo/.opam/4.04.0/windows-sysroot/lib/easy-format -I src easy_format.cmx biniou.cmxa bin/bdump.cmx)                                         
File "_none_", line 1:                                   
Error: Files /home/pirbo/.opam/4.04.0/windows-sysroot/lib/easy-format/easy_format.cmx                                
       and /home/pirbo/.opam/4.04.0/lib/ocaml/stdlib.cmxa
       make inconsistent assumptions over implementation Printf

So, what is the trendy way to cross-compile?

One can read on Overview — Dune documentation

cross-platform: as long as your code is portable, Jbuilder will be able to cross-compile it (note that Jbuilder is designed internally to make this easy but the actual support is not implemented yet)

So I guess, the need is know, I’ll just have to be patient.

This has now landed! (for future reference) https://github.com/ocaml/dune/pull/380
and here’s the docs update https://github.com/ocaml/dune/pull/434

2 Likes