Prologue

OCaml looks like a really cool type-safe language that supports pure functional, imperative and even object-oriented programming styles. The syntax is different without a lot of curly braces and semi-colons for those used to a C style language.

The thing that upsets me the most is trying to find decent and concise installation instructions, especially for OS/X. Everybody and their mother seem to have a slightly different way of installing the software and make it work. I’m going to add my own set of instructions to add to the confusion and have a place that I can go to be able to get things working without having to go to a dozen different sites.

Install

Homebrew

I like Homebrew so we’ll start with getting that up and running. If you already have Homebrew installed, then feel free to proceed.

Open up a terminal window and try the following:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

You should be able to follow the prompts or look here for additional help.

Package Installation

To get the ocaml package installed:

brew cleanup
brew update
brew install ocaml --without-x11 openssl opam

We install ocaml with the --without-x11 so we don’t have to install XQuartz. We install openssl since the one provided by Apple is old and insecure.

The installation will take a few minutes, but should complete without any issues.

Post-Install

We have a few tasks that will allow us to install packages from OPAM.

We will need to initialize opam

opam init

opam by default will add an entry to your .bashrc to setup pathing and what not. Which is okay under Linux, but OS/X doesn’t deal with that properly. That means we have to add a few lines to our .bash_profile in order for OS/X to pick put the changes.

You can copy the contents of the new .bashrc to your .bash_profile or add the following to your .bash_profile.

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

OCaml Packages of Interest

There are some packages that the majority of people use when dealing with ocaml. Others are highly recommended.

opam install core lwt sexplib ounit utop

BONUS!

One of the reasons I’m getting into OCaml ( and Xen for that matter ) is because of Mirage OS and how it generates unikernels which are very lean single function virtual machines or appliance.

The documentation isn’t all there, which is understandable given how young the project is. There are a few extra steps to make things work.

First is adding the tun/tap drivers to OS/X. You can download the kernel drivers from the SourceForge project and install them as you would anything else.

Yes, there is a brew package available for those drivers, but I could not get them to work correctly or at all.

As of writing this, the mirage packages in the primary opam repository are pretty old and don’t really work all that well. We can add the mirage development repository until such time they get some dependency issues resolved and push the new libraries up and out.

opam remote add mirage git://github.com/mirage/mirage-dev

Then install these packages:

opam install mirage ssl 

You should free to run about the cabin or start following the documentation at the Mirage OS site.

Caveats

There are a few things to be aware of though. Some of the examples, including the static_website make use of the tun/tap drivers to handle the networking. OS/X doesn’t make it easy to work with those devices so I’ll document the works for me path.

You’ll need to configure the tap device with:

sudo ifconfig tap0 10.0.0.1 255.255.255.0

And when you run the mirage command, or the try to run the native binary you will need to use sudo to get the executable to connect to the new tap device. From there you can browse or ping the running appliance ( typically at 10.0.0.2 ).



Published

30 October 2014

Category

software

Tags