The cross compilation terminology is always confusing. You want to compile using a linux executable that run under MacOS/Windows, don’t you?
If so, the title of your post should be “Cross compilation to OSX/Windows from linux”.
TL;DR:
- Can I compile an executable for windows using an unix machine? Yes, have a look at https://github.com/whitequark/opam-cross-windows but it is in danger.
- Can I compile an executable for MacOS using a linux machine? I’m not aware of anything
Explanation:
In the past years, some energy has been put in the OCaml compiler itself to make it cross compilation friendly.
As a complete cross-compilation environnement is concern. https://github.com/whitequark/opam-cross-windows, https://github.com/whitequark/opam-cross-ios, https://github.com/whitequark/opam-cross-android are attempts to provide some.
Efforts are not coordinated and there exists also an older but still somehow maintained and containing a different set of packages https://github.com/vouillon/opam-windows-repository. (At the first glance, let say it is better for packages that contains/depend upon C code) I wish the 2 can merge on day if they survive the current OCaml ecosystem tsunami: jbuilder
.
Jbuilder
, the new cool build system widely discussed on this channel comes with a lot promisses (and pretty good achievement already) but, in order to solve one day the problem of cross compilation in completed case, it is not compatible with the way we implemented cross-compilation in simple ones…
Concretely, it made the choice to not use ocamlfind
to “choose” the compiler it uses. Therefore, you have no way for now to ask it to use the cross-compiler instead of the “regular” compiler! Go at https://github.com/janestreet/jbuilder/issues/144 to stay tuned on the issue.
Problem: critical OCaml libraries are now compiled using jbuilder (9 of the 39 packages of opam-cross-windows). Therefore, you cannot cross-compile their cutting edge version (for now) and you won’t be able to follow the evolution of the ecosystem if you want to cross compile.
To take a concrete example, without real responsibility from lwt developers (but the one to rush changing their build system while they had a working one ) when the next major version of Lwt will go out in a few months, Lwt dependencies will have to choose between staying in lwt 3 forever or not being cross compilable…