Compile Ruby 1.9.2 and Ruby 1.9.3 with Clang (Xcode 4) under RVM on Mac OSX 10.6.7 or 10.7.0

In my previous post, I tried to compile Ruby 1.9 but didn’t have much success, although the compilation completes, the RoR doesn’t function correctly (I got Segmentation fault while running ‘rails s’). Today post will be about my second attempt to get Ruby 1.9 compiled with more recent version of clang, ver 2.1 (included in XCode 4.1 by Apple – free to download from AppStore if you were on OSX Lion).

clang 2.1 is based on LLVM 3.0SVN. I’ve done few researches on this and been reported people get 1.9.1-p0 successfully compiled but none has success with 1.9.2-p290. I am very curious if clang 2.1 would get all nasty exceptions resolved.

Firstly, you need to download Xcode 4.1.1 from Apple website. Then set up Environment like this:

export rvm_clang_flag=1
export CC=/Developer/usr/bin/clang
export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments
export PATH=/Developer/usr/bin:$PATH

Secondly, you need RVM installed and ruby packages fetched. For this experiment, I fetch both stable 1.9.2-p290 and 1.9.3-p0 version:

rvm fetch 1.9.2
rvm fetch 1.9.3

Now let’s get started, issue configure and install command for RVM:

ruby 1.9.2-p290

rvm install 1.9.2 --reconfigure --debug -C --enable-pthread --with-gcc=clang

After running for few minutes, I got a whole full screen with garbage code and junk, checking log file indicates that clang failed to get 1.9.2 compiled. The log can be found here

That doesn’t look good, at least I got 1.9.2rc1 successfully compiled with clang 1.5 before. So there must be changes in p290 that breaks.

ruby 1.9.3-p0
Come to think of it, there might be high chance ruby 1.9.3 has resolved all those mysterious issues so why not give it a try?

First, you need to install libksba first, I no longer use portage, so in this article I use Homebrew

brew install libksba

Now we install Ruby

rvm install 1.9.3-p0 --reconfigure --debug -C --enable-pthread --with-gcc=clang
rvm reload
rvm use 1.9.3-p0

Yes! Ruby compilation reaches the end of the process though there is a minor issue. The process seems break rvm and a quick fix is to close the Terminal and re-open.

Now let’s give RoR a try with 1.9.3. And bravo, it works. Soon Apple will switch to use clang 3.0 by default in future release of Xcode, seeing Ruby 1.9.3-p0 compiled indicates a positive sign that OSX always be a favourite platform for Ruby/RoR development.
RubyOnRails 3.0.4, Ruby 1.9.3-head (11-02-2011) compiled with clang 2.0 (XCode 4.0 GM)


About Jones Lee

Nothing much about me..

5 responses to “Compile Ruby 1.9.2 and Ruby 1.9.3 with Clang (Xcode 4) under RVM on Mac OSX 10.6.7 or 10.7.0

  1. Very nice article! Thanks for the post! At least I know that Clang could be able to compile Ruby after all.

  2. Pingback: rails 3.1 과 3.0 환경 같이 설정하기 | andy's blog

  3. fixnichols

    its a mac, who cares

  4. Pingback: rails 3.1 과 3.0 환경 같이 설정하기 | msk

  5. Pingback: rails 3.1 과 3.0 환경 같이 설정하기 « mrmsk

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: