Mirah, the brainchild of Charles Nutter, piqued my interest a while back (statically typed Ruby? Yes please!), but I lost interest pretty quickly because a) it looked like an afterthought compared to JRuby at the time; and b) it took me more than ten minutes to figure out how to build it.
The good news is that there’s recently been a couple of new releases of Mirah, with versions 0.0.6 and 0.0.7 being released over the weekend. It looks like Mirah is actually going to get a bit of airtime, so I figured it was time to figure out how to get this thing building. So here’s how I did it.
Before you start
Before you do anything, you’re going to need git, a JDK and ant. Getting these guys installed is outside the scope of the tutorial, but there’s plenty of resources on the web to help you along the way.
Build JRuby (from source)
I cloned the jruby git repository:
$ git clone git://github.com/jruby/jruby.git
It may take some time for the full repo to be cloned (you might want to consider git’s –depth option). I imagine building from a tarball would also work just as well, so you might want to try that.
Once that’s done, you’ll need to build it using the jar-complete target:
$ cd jruby
$ ant jar-complete
Again, this may take some time. Grab a coffee.
I then had to explicitly install the rake gem in my build of jruby.
$ bin/jruby -S gem install rake
We don’t actually need to build bitescript, we just need the checked out source folder present in the same directory as the jruby directory. Mirah’s build scripts currently require everything to be set up in a particular way, so this is important! (i.e. if jruby was checked out to /home/me/code/jruby, bitescript should be checked out to /home/me/code/bitescript).
Simply clone the repo from github:
$ cd .. # back to the directory above “jruby”
$ git clone git://github.com/headius/bitescript.git
The moment you’ve been waiting for! Grab a copy of the Mirah source code:
$ git clone git://github.com/mirah/mirah.git
(to reiterate: Mirah’s build scripts require the bitescript, jruby and mirah directories all be in the same directory)
Then build it using our JRuby build:
$ cd mirah
$ ../jruby/bin/jruby -S rake jar:complete
If all goes well, you should now have dist/mirah-complete.jar, which is all you’ll need to run “Hello World”.
Running Hello World
Put the following code in a file called helloworld.mirah:
puts “Hello World”
Now you can run it via the command line:
$ java -jar dist/mirah-complete.jar run helloworld.mirah
Compiling Hello World
You can also compile your program to a Java class using your newly built Mirah jar, and then run it using java:
$ java -jar dist/mirah-complete.jar compile helloworld.mirah
$ java -cp . Helloworld
Note that running the “Helloworld” class doesn’t require any external dependencies: the generated class files are currently entirely independent of any runtime outside of Java itself. So you only need the Mirah jars around at compile time. Neat!
Hopefully this stuff saves somebody from doing what I did months ago and simply walking away from Mirah in frustration after struggling with it for ten minutes. It’s a cool little language, and absolutely worth a play. Now, time to try and contribute some patches…