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:
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 http://pastebin.com/bwZ4UYiY
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.
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.