Compiling Ruby 1.9 with GCC 4.4

28 04 2009

Got the 1.9 pickaxe, so it’s definitely time to get Ruby 1.9 installed alongside 1.8. It turns out that if you try to build Ruby 1.9 with GCC 4.4 by means of the typical ./configure; make; sudo make install, you will hit a wall on the make step. I’m running into this while evaluating Fedora11 snap1, still in beta. The issue is that GCC 4.4 introduces a few changes that will impede ruby 1.9 from compiling without some minor adjustments.

These are the steps to get going:
1. Download, verify and unpack Ruby 1.9.
$ wget
$ md5sum ruby-1.9.1-p0.tar.gz
50e4f381ce68c6de72bace6d75f0135b ruby-1.9.1-p0.tar.gz #verify that hash matches
$ tar xvf ruby-1.9.1-p0.tar.gz
$ cd ruby-1.9.1-p0

At this point, we have verified and extracted the ruby 1.9 source code. Go ahead and create your platform’s compile configuration. There are many flags you can pass. To see them all, type ./configure –help. I’ve chosen to keep the libraries in their default locations, and suffix the binaries with ’19’ (leaving your 1.8 ruby installation intact). Some folks prefer to install it on a completely different path to avoid this very issue, by using the –prefix-path flag instead. That’s up to you.
./configure --program-suffix=19 --disable-pthread
At this point, you may be tempted to type “make”. If you do, you’ll get the following error:

cont.c:90:6: error: #elif with no expression
cont.c:270:6: error: #elif with no expression
cont.c:317:6: error: #elif with no expression
make: *** [cont.o] Error 1

The resolution is to edit the cont.c file to go on. Open it up, and change the lines 90, 270 and 317 from #elif to #else.

Now, carry on as usual:
$ make
$ make test #make sure everything's sane
$ sudo make install #or su -, or whatever it is you kids use to gain admin privileges these days

You’re done. irb will open up the console on ruby 1.8, and irb19 will open it in ruby 1.9. Similarly, point your scripts to the ruby19 binary instead of ruby.

You can now try out some of the new ruby 1.9 features in irb19:
irb(main):001:0> [1,2].inject(:+) #new injections
=> 3
irb(main):002:0> {a: 'a_val', b: 'b_val'} #new hash synthax
=> {:a=>"a_val", :b=>"b_val"}
irb(main):003:0> p = -> a,b,c {a+b+c} #lambda shorthand
=> #
=> true
irb(main):005:0> beta_string = 'ß' #utf-8 strings
=> "ß"
irb(main):006:0> π = 3.14 # and variables
=> 3.14
irb(main):007:0> π * 5
=> 15.7

Now, let’s see what the fuzz is all about. I tried running the the full ruby benchmark suite, but I got a nasty kernel panic:Apr 27 23:03:45 hgnux kernel: Critical temperature reached (95 C), shutting down.Guess I need a laptop that sucks less to run it. This isn’t over though: I’ll stick my laptop in the freezer if I have to, just to run the full benchmark suite.

Instead, let’s run and benchmark the most inefficient piece of crap on both versions of ruby. Recursion will do the trick. Let’s calculate factorials and fibonaccis left and right. Save this script somewhere:

require 'benchmark'
include Benchmark
def fact(n)
  n == 1 ? 1 : n*fact(n-1)

def fib(n)
  if n == 0 || n == 1
    fib(n-1) + fib(n-2)

puts "Ruby #{RUBY_VERSION} patch #{RUBY_PATCHLEVEL}"

bm do |r| do 
    (1..35).each do |n|

Now, invoke it with both your ruby and your ruby19 binaries:

Ruby 1.8 vs. Ruby 1.9 running recursion.rb

Ruby 1.8 vs. Ruby 1.9 running recursion.rb

$ ruby recursion.rb 
Ruby 1.8.6 patch 287
      user     system      total        real
155.320000  45.950000 201.270000 (229.181959)

$ ruby19 recursion.rb 
Ruby 1.9.1 patch 0
      user     system      total        real
 16.030000   0.100000  16.130000 ( 16.852891)

Sweet! I’ve also included the results of vmstat + vmplot of these runs. Most impressive is the minimized number of system interrupts on the ruby 1.9 version.

Ruby downloads:
GCC 4.4 porting notes:
Extended vmplot:
Ruby benchmark suite:

Really silly percentage calculation in Ruby

22 03 2009

Content moved to

Upgrade to Rails 2.2 on Windows

17 01 2009

A glimpse at the bottom of the Rails 2.2 release notes show that Rails 2.2 require RubyGems version 1.3.1.

After failing to simply gem update –system, try the following:

> gem install rubygems-update
> cd c:\ruby\lib\ruby\gems\1.8\gems\rubygems-update-1.3.1
> ruby install.rb

This will successfully update RubyGems, and you should finally be at:

> gem -v

Now, we can simply do

> gem install rails
Successfully installed activesupport-2.2.2
Successfully installed activerecord-2.2.2
Successfully installed actionpack-2.2.2
Successfully installed actionmailer-2.2.2
Successfully installed activeresource-2.2.2
Successfully installed rails-2.2.2
6 gems installed
Installing ri documentation for activesupport-2.2.2...
Installing ri documentation for activerecord-2.2.2...
Installing ri documentation for actionpack-2.2.2...
Installing ri documentation for actionmailer-2.2.2...
Installing ri documentation for activeresource-2.2.2...
Installing RDoc documentation for activesupport-2.2.2...
Installing RDoc documentation for activerecord-2.2.2...
Installing RDoc documentation for actionpack-2.2.2...
Installing RDoc documentation for actionmailer-2.2.2...
Installing RDoc documentation for activeresource-2.2.2...

So far so good. Now, if you froze an earlier rails version in your app, setting it free is as simple as:

rake rails:unfreeze

At this point, update your config/environment.rb to rails version 2.2.2, and then run:

>rake rails:freeze:gems
(in C:/code/app)
Freezing to the gems for Rails 2.2.2
rm -rf vendor/rails
mkdir -p vendor/rails
cd vendor/rails
Unpacked gem: 'C:/code/app/vendor/rails/activesupport-2.2.2'
mv activesupport-2.2.2 activesupport
Unpacked gem: 'C:/code/app/vendor/rails/activerecord-2.2.2'
mv activerecord-2.2.2 activerecord
Unpacked gem: 'C:/code/app/vendor/rails/actionpack-2.2.2'
mv actionpack-2.2.2 actionpack
Unpacked gem: 'C:/code/app/vendor/rails/actionmailer-2.2.2'
mv actionmailer-2.2.2 actionmailer
Unpacked gem: 'C:/code/app/vendor/rails/activeresource-2.2.2'
mv activeresource-2.2.2 activeresource
Unpacked gem: 'C:/code/app/vendor/rails/rails-2.2.2'
cd -

Now run your tests suite. You do have tests. You do.

Bonus: If you are stuck on windows, do yourself a favor and use console2 for a half decent command prompt. Easier to select/paiste text, resize the window (no full screen (!!!)), tabs, and other goodies.

Installing FANN and ruby-fann on Fedora Core 9

1 08 2008

Content moved to

Cannot connect to SQL Server 2005 Express

28 11 2007

Content moved to

Stop spam on sendmail

16 09 2006

Content moved to

How to use Java’s URLEncoder.encode() method

8 09 2006

Content moved to