Meditations on programming, startups, and technology
New Relic

Getting MacRuby’s compiler to work

MacRuby's logoThere is major news in Rubyland today. MacRuby’s team just released their fist beta of version 0.5 (an experimental, still incomplete version of Ruby), which brings JIT, removal of the dreaded GIL (Global Interpreter Lock), native threads, GCD (Grand Central Dispatch) for multicore computing, and a whole new set of features found in the release announcement to the table.

The most important new feature is the presence of a compiler. That’s right, thanks to this release, Ruby code can now become highly optimized executable code. How awesome is that? I can sense that you’re pumped by this news, so why not head over to and download the installation file for yourself? After you’ve done that, the next thing you’re going to want to do is run a small test like the following:

$ macrubyc world_domination.rb -o world_domination
Can't locate program `llc'

Oh noes! llc is a tool that ships with the LLVM (upon which MacRuby is built), however it’s not included with MacRuby’s installer (it will be in the future). But fear not my friends, there is a solution:

$ svn co -r 82747 llvm-trunk
$ cd llvm-trunk
$ ./configure
$ sudo env UNIVERSAL=1 UNIVERSAL_ARCH="i386 x86_64" ENABLE_OPTIMIZED=1 make install

If your machine does not have 2 cores, remove the -j2 option from the fourth line or adjust the number accordingly.

The compilation phase may take a couple of centuries, depending on your machine’s speed, but it should eventually build the LLVM. 😛 llc will be placed in your PATH, and you’ll finally be able to compile Ruby code and obtain an executable to help you carry out your world domination plans.

$ macrubyc world_domination.rb -o world_domination
$ ./world_domination

If you enjoyed this post, then make sure you subscribe to my Newsletter and/or Feed.

receive my posts by email

5 Responses to “Getting MacRuby’s compiler to work”

  1. Diego Virasoro says:

    Yep… it looks like it’s really getting up to become a pretty awesome piece of code.

    If/when you have some time, it would be nice to see how the new .5 fairs against the rest in the great ruby shootout.

  2. jc says:

    Worked as expected. Thats pretty incredible! Thanks for the instructions Antonio.

    Would love to see you redo some of your earlier benchmarks using the compiled version of macruby 0.5 and see how it fares.

  3. Patrick says:

    Thats pretty cool. I think there are some restrictions. A simple hello world worked fine. However, a generic tcp server did not.

  4. Yes, Patrick, it’s very much experimental at this point. If a library you require is not compiled yet, the compilation won’t work.

  5. Eli says:

    Hey, I’m running into issue after issue with ./configure.

    Right now I’m getting “checking for C compiler default output file name… configure: error: C compiler cannot create executables”.

    In the error log, it looks like the problem is:
    configure:2826: $? = 0
    configure:2833: gcc -V >&5
    gcc-4.0: argument to `-V’ is missing
    configure:2836: $? = 1
    configure:2859: checking for C compiler default output file name
    configure:2886: gcc conftest.c >&5
    ld: library not found for -lcrt1.10.5.o
    collect2: ld returned 1 exit status
    configure:2889: $? = 1

    Any ideas?


Leave a Reply

I sincerely welcome and appreciate your comments, whether in agreement or dissenting with my article. However, trolling will not be tolerated. Comments are automatically closed 15 days after the publication of each article.

Copyright © 2005-2014 Antonio Cangiano. All rights reserved.