The topic will be functional programming with emphasis on Haskell. I'm also writing my own language called Mikan and hope to share progress here. So let's have fun!

Saturday, May 22, 2010

Cabal Installing Haskell LLVM Module on Mac OSX

I got stars in my eyes when I saw the LLVM module for Haskell developed by Bryan O’Sullivan and Lennart Augustsson. Think of the possibilities!

Just as a bit of clarification, there is also a recent buzz around the net related to LLVM and GHC/Haskell due to the LLVM code-gen functionality integrated into GHC by David Terei in his thesis. Although that is definitely very cool, it's different than the LLVM module.

There are a few posts by Bryan and Lennart that discuss the LLVM module here (which I'm listing for completeness and also for my own reference):
Unfortunately, despite my initial excitement, I wasn't able to get the LLVM module to ever install via cabal ... until now that is!

I thought I'd write a post on how I did it in case anyone else is having similar issues.

First, you need to install LLVM. I took some cues from the install guide for unladen swallow (the fast Python implementation on LLVM and using a jit compiler that Google is sponsoring) and also from the LLVM getting started page.

Specifically, I installed LLVM 2.7 and also the gcc front end (not required to my knowledge but looked interesting/useful). Here are the commands I used:

> wget 'http://llvm.org/releases/2.7/llvm-gcc-4.2-2.7-x86_64-apple-darwin10.tgz'
> wget 'http://llvm.org/releases/2.7/llvm-2.7.tgz'
> tar xzf llvm-gcc-4.2-2.7-x86_64-apple-darwin10.tgz

Once you've untarred the gcc binaries, move them to the location you want to install them at. Be careful with just dropping folders onto existing folder hierarchies on Mac -- this has an effect of replacing the target folders as opposed to adding the contents to the existing tree (a discovery learned through tears I can tell you). Continuing:

> tar xzf llvm-2.7.tgz
> mkdir llvm_build
> cd llvm_build
> ../llvm-2.7/configure --prefix={prefix path if not installing to default} --with-llvmgccdir={path to llvm-gcc binaries}

Note: if you'd like the O'Caml bindings, add "--with-ocaml-libdir={path to your ocaml library}". For example, the values for me were:

* --prefix=/Users/{uname}/.local --with-llvmgcdir=/Users/{uname}/.local --with-ocaml-libdir=/usr/local/lib/ocaml

If you're installing to the standard locations and installed the gcc front end in a standard area on the path, you don't need the above configuration flags. I decided to install to a custom location and so required the flags myself.

At this point you are ready to compile LLVM. I had successfully downloaded and built llvm many times before and confirmed the tools worked (llc, lli, etc.). However, I could never succeed in getting the Haskell LLVM module to build. The big breakthrough came from this e-mail which indicates a need to declare the variable "UNIVERSAL" as follows:

> UNIVERSAL=1 gmake -j4

This will take a while to compile. The 4 after the j flag indicates the number of processors to use. Once compilation completes, you need to:

> gmake install
> cabal install llvm

and you're done!

1 comments:

  1. You should see more on that module soon. It will be used in GHC's LLVM backend :)

    ReplyDelete

About Me

My Photo
A comic artist, sometimes programmer, and engineer in the field of renewable energy.

Tags

© 2009, 2010 Michael Patrick O'Keefe, all rights reserved

Interesting Shtuff

Followers