[ANN] Easy cross compilation using esy

Hello,

I’ve been working on this for a couple of months now, and now it is ready for an initial announcement of my tools to cross compiling OCaml and ReasonML Native.

GitHub - EduardoRFS/reason-mobile

What it can do

Out of box it can cross compile most dune and topkg, packages available on opam for a couple of platforms, there is also patches for popular packages.

You can also compile opam packages by making an wrapper, like

misc: detect CPU architecture from C compiler by EduardoRFS · Pull Request #84 · mirage/mirage-crypto · GitHub

Limitations

Your package should build with OCaml 4.10, and all the packages that are built for the host will also be build for the target, so sometimes you need to fix a package that you will not use directly.

Some packages you will need to pin to a dune-universe fork version

How to use it

## compile your project
esy

## generate the wrapper
esy add -D generate@EduardoRFS/reason-mobile:generate.json
esy generate android.arm64

## build for android.arm64
esy @android.arm64

Platforms

All of the following are tested from Linux and macOS, but I would suppose that FreeBSD should be also working as a build system.

Targets
android.arm64
android.x86_64
ios.arm64
ios.simulator.x86_64
linux.musl.arm64
linux.musl.x86_64

What I tested

In the past I was able to build Revery the UI framework for Android and iOS

But recently I did compile esy the package manager itself for all of the following platforms above from an Arch Linux x86_64 and macOS Catalina x86_64. Including iOS, with the right version of OCaml it will run inside of the new macOS ARM64 and inside of a jailbroken iPhone.

31 Likes