Building OCaml on Haiku

What has to be a niche of a niche post wise, I was intrigued when I spotted this post recently that someone had built OCaml for Haiku. I'd been playing with Haiku a little recently, as I wanted to understand its file-system, and so I thought I'd have a go. I turns out it's quite simple, and although the above post does kinda tell you what you need, there's a few gaps, so this post is just recording what I did. But all credit has to go to Sylvain Kerjean for that original post which gets you most the way, this is just trying to make it easier for me to cut and paste later!

First up:

Ensure /boot/home/config/non-packaged/bin is on your PATH variable.

Get a checkout of OCaml from https://github.com/ocaml/ocaml.

Configure it with the appropriate prefix, make, and install. It really does just work!

$ export PATH=$PATH:/boot/home/config/non-packaged/bin
$ git clone https://github.com/ocaml/ocaml.git
$ cd ocaml
$ ./configure --prefix=/boot/home/config/non-packaged
...
$ make
...
$ make install

Now you have ocaml, you're almost certainly going to want to install opam, OCaml's package manager, also. Thankfully that also mostly works, with the one caveat that opam needs some OCaml modules installed to build, which you could install with opam, but you don't have it yet! Thankfully there's an option for that:

Get a checkout of opam from https://github.com/ocaml/opam.

Configure it with the prefix and vendor flags, then make and install. Also really easy!

$ cd ..
$ git clone https://github.com/ocaml/opam.git
$ cd opam
$ ./configure --prefix=/boot/home/config/non-packaged --with-vendored-deps
...
$ make
...
$ make install

At this stage, you're almost good to go. Opam will need a couple of tools installed before it'll work:

$ pkgman install rsync getconf
$ opam init

And now you're good to go! Much to my surprise I was able to even get running my SDL2 based retro graphics library for OCaml working very quickly. I just had to make sure I had a few extra _devel packages installed for things like SDL2 and libffi.

It is however, increadably slow - my graphics library isn't very well optimised, as usually on modern hardware it doesn't need it to push old-school VGA like graphics around, but running natively on my AMD Razen machine it was really quite poor, low single-digit frames per second. In part this I assume is related to Haiku not knowing about my fancy NVIDIA graphics card, and just using the stock framebuffer driver, and in part because OCaml doesn't know about Haiku enough to build a native binary and is instead using the bytecode backend.