Building Ruby Extensions with Rake

Posted by code_monkey_steve, Sat Sep 09 12:36:00 UTC 2006

When I began working on RDBXML (a Ruby extension for BDB and BDBXML), I quickly became frustrated with the “standard” extension building, e.g. mkmf. I found the configration cumbersome, the intermediate Makefile a bit krufty, and the fact that you can only build one extension (i.e. .so) a complete show-stopper.

I’m a big fan of Rake as a Make replacement (and an excellent example of extending Ruby to a common problem domain), but I was a bit surprised to find that it didn’t come with predefined rules to build Ruby extensions and, in paricular, SWIG -generated wrappers. I have taken steps to rectify this oversight with a few handy Rake tasks.

At the moment, the tasks are a part of the RDBXML project, hosted by RubyForge . There is documentation, and you can view the latest version in SVN here.

Usage is simple enough:
require ‘rake/swigextensiontask’ desc “Build the BDB interface extension” Rake::SWIGExtensionTask.new :db do |t| t.dir = ‘ext’ t.link_libs += [‘db’, ‘db_cxx’] end

This will build db.so, from the db.i SWIG interface file in the ext directory, linking-aginst db.so and db_cxx.so. For a full usage example, see the Rakefile for RDBXML.

Filed Under: Projects | Tags: extension rake ruby

Comments