Cross compiling go on Mac OS X

After a lot of fun with this I thought I would write a quick note onĀ setting up your mac for cross compiling with go lang.

I make 2 assumptions here, firstly you use homebrew and secondly you are only writing pure go code (no calling c functions etc). With that in mind the complex process boils down to this:

brew install go --with-cc-all

Yep, that’s it. With that one line you get all the go compilers, if you only want common platforms you can save yourself some space and just run:

brew install go --with-cc-common

Personally I like to couple this with a makefile that allows me to generally build and test on my mac, but when I really want to I can create cross compiled binaries. I like to run a makefile that looks a bit like this:

all: install

build:
    go build ./...

install:
    go install ./...

c-install:
    GOOS=linux GOARCH=amd64 go install
    GOOS=darwin GOARCH=amd64 go install
    GOOS=windows GOARCH=amd64 go install
    GOOS=windows GOARCH=386 go install

And that should be about it to be running a cross compiling go setup!

Setting up OS X for Clojure Development

Developing in clojure is an absolute pleasure, however setting it up is rarely as easy. In this guide I will take you through the steps to get OS X up and running with Clojure and Leiningen (the Clojure build system).

Install Macports

Macports is a great package manager for OS X, it has all you need to get up and running. Install Macports from hereĀ http://www.macports.org/install.php

Install Clojure

To install clojure you need to run this as root:

sudo port -R install clojure

When you run that you will be asked for your password, after that it will automatically install. The -R will upgrade any dependencies too, just to keep things tidy.

Install Leiningen

Leiningen is the build tool for clojure, like maven is for java. In fact it even plays nicely with maven! Install it as such:

sudo port -R install leiningen

Once its installed it comes with a 2nd step you need to run:

lein self-install

Test your work

After which you are done. We’re going to test this by creating a new project using leiningen and proving the template tests fail as they are designed to do.

lein new testing
cd testing
lein test

If you see the line:

FAIL in (replace-me) (core.clj:6)

Then you have a working setup, welcome to the world of clojure!