## Sunday, August 11, 2013

### Building OCaml programs in Cloud9 IDE

Cloud9 IDE is one of several new cloud-based products providing the ability to edit, build, test, and deploy code through a collaborative web application. Cloud9 IDE has one especially powerful feature: each workspace (i.e. project or repo) has a Linux home directory persisted along with the code and other settings, and you get a full bash terminal in this directory with modest but usable resource limits. This means it's possible to install and use a full OCaml toolchain inside, much like my previous effort on Travis CI.

I prepared a script to automate the process of installing OCaml and OPAM inside a Cloud9 IDE workspace. Enter into the terminal in any workspace:
curl -L https://raw.github.com/mlin/c9-ocaml/master/c9-ocaml.sh | bash -ex
eval \$(opam config env)
The OCaml toolchain and OPAM are then ready to go. Here's a screenshot of compiling and running 'Hello, world!':

OCaml syntax highlighting was already built-in, interestingly enough. A more elaborate example, where I used the site's GitHub integration to import ForkWork and ran the unit tests, which need OPAM packages like oasis and kaputt.

Some difficulties I encountered:
• The script builds the OCaml toolchain from source, which takes a solid 15-20 minutes for each new workspace.
• I couldn't immediately figure out a way to create binary packages due to some coincidental quirks: various OCaml binaries seem to be tied to the absolute installation path specified by their build configuration, while in Cloud9 IDE we can't write outside of the workspace home directory, the path of which is workspace-specific.
• Meanwhile there's some kind of nix-based package manager going on, but I couldn't find a way to extend it.
• Native-code camlp4 (make camlp4opt) doesn't successfully compile in the workspace; I'm not sure why, but perhaps it's the RAM ceiling. The c9-ocaml script jumps through some hoops to install the bytecode but not native-code version of camlp4, while installing both versions of the other tools.
Cloud9 IDE seems to have been originally designed for front-end and non-compiled back-end (Node.js, Rails, Django, etc.) development, and some typical IDE features for compiled languages are lacking. Improvement here is hopefully on their roadmap since it's touted by one of their competitors. That stated, the existing feature set is quite comparable to my lightweight Sublime/xterm flow.

I'd also like to see Cloud9 IDE provide an option to provision root access in a VM/cloud instance (as in Travis CI) or LXC container (as in Heroku, and here at DNAnexus), enabling full access to mainstream package repositories like apt. There appears to be an existing option in their premium tier where their back-end can ssh into some machine the user sets up herself, but it would be far more convenient to provide an elastic pool of VMs.