You are reading "the Zuulcat Archives". These are publications written by Martin Mazur between 2006 - 2015.

Future writings will be published on mazur.today.



The Zuulcat Archives


Installing IronRuby from Source on Mono

 Jun 6, 2011  |   Filed under: Software Development  |   Tags: .NET, IronRuby, mono, Programming, Ruby


This whole thing started as an effort to get IronRuby on board the rvm train. I started looking around for documentation on how to build/install IronRuby from source with Mono but the blogs and documentation I found where mostly outdated and full of broken links. I guess this is due to the bumpy ride IronRuby has had with owners, repositories and build processes changing several times in a short period of time.

In order to get IronRuby on rvm I needed to figure out how exactly IronRuby builds. At first this seemed like a trivial task however it soon proved to be a bit more complicated.

I want to share my findings with everyone and hopefully I'll save someone a bit of time. The process I describe below works with IronRuby source tagged "v1.1.2" and "v1.1.3". It also works with head, which at the time of writing is revision 8099de3e15b5c28f32fd.

I've tried the process on both OSX and Ubuntu and it seems to work fine but please let me know if something breaks down for you.

The basic outline of the build and installation processes is:

  1. Check Prerequisites
  2. Get the Source
  3. Build IronRuby
  4. Gather Resources
  5. Create Scripts
  6. Configure IronRuby
  7. Hook Everything Up

Check Prerequisites

To build and install IronRuby from source you will need git (obviously) and Mono with C# 4.0 compatibility and developer tools.

If you have Mono 2.10 you should be safe. The Mono binaries you want to make sure are on your system are mono, dmcs and xbuild.

$ mono --version

Mono JIT compiler version 2.10.1 (tarball Fri Feb 25 15:56:49 MST 2011)
Copyright (C) 2002-2011 Novell, Inc and Contributors. www.mono-project.com
	TLS:           normal
	SIGSEGV:       normal
	Notification:  Thread + polling
	Architecture:  x86
	Disabled:      none
	Misc:          debugger softdebug 
	LLVM:          yes(2.9svn-mono)
	GC:            Included Boehm (with typed GC)
$ dmcs --version

Mono C# compiler version 2.10.1.0
$ xbuild /version

XBuild Engine Version 2.10.1.0
Mono, Version 2.10.1.0
Copyright (C) Marek Sieradzki 2005-2008, Novell 2008-2011.

The best way to get mono 2.10 is to use one of the latest stable binary builds found under downloads on the mono page. If that fails you can try building it yourself.

Get the Source

After figuring out the authoritative repository for IronRuby this was probably the easiest part. I've decided to install my IronRuby into /usr/local/ironruby, where you decide to put it is absolutely up to you.

$ mkdir /usr/local/ironruby
$ cd /usr/local/ironruby

$ git clone git://github.com/IronLanguages/main.git src
$ cd src

If you want to build from a specific tag just checkout that tag

$ git checkout v1.1.3

Build IronRuby

We will be using xbuild to build IronRuby. This is the equivalent of msbuild on a Windows system. The build itself is simple, it's only one command and shouldn't cause you any trouble.

$ xbuild /p:Configuration=Release Solutions/Ruby.sln

It will most likely generate some warnings but those are safely ignored. The binaries should now be built in bin/Release.

Gather Resources

Gathering the resources is basically just copying all the files needed for a full installation into the appropriate folders. The two important folders that IronRuby uses are bin, for binaries, and lib, for libraries, simple.

Let's start with the lib directory since this is the simpler one of the two. The lib directory holds the ruby libraries that are used by IronRuby. This is mostly Ruby 1.9.1 StdLib with some modifications but also some specific IronRuby libraries.

$ mkdir /usr/local/ironruby/lib
$ cp -R /usr/local/ironruby/src/Languages/Ruby/StdLib/* /usr/local/ironruby/lib

The bin directory on the other hand requires files from two different places.

$ mkdir /usr/local/ironruby/bin

First, of course, we need the binaries we just built.

$ cp /usr/local/ironruby/src/bin/Release/* /usr/local/ironruby/bin

In addition to those we also need some other script binaries found in the IronRuby source. There are several *.bat files that can safely be skipped since I'm assuming we are building and installing on a *nix system.

cd /usr/local/ironruby/src/Languages/Ruby/Scripts/bin/
cp !(*.bat) /usr/local/ironruby/bin

We are almost done with the bin directory but we still need a couple of scripts that are not included in the repository. These are not really complicated scripts so we can just add them manually.

Create Scripts

The scripts I'm referring to are ir, iirb, igem, iri and irdoc. In order to create the first script, ir, we need to know the full path to our mono binary.

$ which mono
/usr/bin/mono

Now we can create the script ir in /usr/local/ironruby/bin with the following content

#!/bin/sh
exec /usr/bin/mono /usr/local/ironruby/bin/ir.exe $@

The other scripts are all similar so I'll just list them below.

iirb:

#!/bin/sh
exec /usr/local/ironruby/bin/ir /usr/local/ironruby/bin/irb $@

igem:

#!/bin/sh
exec /usr/local/ironruby/bin/ir /usr/local/ironruby/bin/gem $@

iri:

#!/bin/sh
exec /usr/local/ironruby/bin/ir /usr/local/ironruby/bin/ri $@

irdoc:

#!/bin/sh
exec /usr/local/ironruby/bin/ir /usr/local/ironruby/bin/rdoc $@

Don't forget to make your scripts executable.

$ chmod ug+x /usr/local/ironruby/bin/ir 
$ chmod ug+x /usr/local/ironruby/bin/iirb 
$ chmod ug+x /usr/local/ironruby/bin/igem 
$ chmod ug+x /usr/local/ironruby/bin/iri 
$ chmod ug+x /usr/local/ironruby/bin/irdoc

Configure IronRuby

IronRuby is a .NET/Mono application and as such has a wonderful *.config file. Fortunately we don't need to do a lot of configuration we only need to set the relative path to the lib directory. The config file is found in /usr/local/ironruby/bin/ir.exe.config

Locate the following line and change the value to your relative librarie path, "..lib" if you have been following along.

<set language="Ruby" option="StandardLibrary" value="..lib"/>

Hook Everything Up

You should now have a built and working install of IronRuby. The only part missing is to add your install path to your system path.

$ export PATH="/usr/local/ironruby/bin:$PATH"

What's Next?

Well this process is tedious, manual and frankly quite hurty. I will continue my dialog with Wayne Seguin of rvm and if all goes well we might get IronRuby with mono on rvm.

Unfortunately I have very limited time in which I can work on these things. If anyone wants to help with IronRuby on rvm please ping me. I would especially like to hear from anyone already working on Mono or IronRuby.