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 MacRuby.com 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 https://llvm.org/svn/llvm-project/llvm/trunk llvm-trunk
$ cd llvm-trunk
$ ./configure
$ UNIVERSAL=1 UNIVERSAL_ARCH="i386 x86_64" ENABLE_OPTIMIZED=1 make -j2
$ 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. :-P 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
MUAHAHAHAHA!

Related Articles:


If you enjoyed this post, then make sure you subscribe to our RSS Feed.

Comments

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

  1. Diego Virasoro on October 8th, 2009 5:57 pm

    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 on October 8th, 2009 6:00 pm

    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 on October 9th, 2009 6:33 am

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

  4. Antonio Cangiano on October 9th, 2009 7:38 am

    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 on October 12th, 2009 10:30 am

    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?

    Thanks,
    Eli

Leave a Reply