mkmf versus mkrf round 1

So in trying to cleanup a ruby extension (rubycube) for release I revisited the build system trying to get a good cross platform build going. The extconf.rb file that I had created was a thing of ugly and in looking around I found mkrf. Now the code for mkrf is very small and clean and it uses a lot of ruby magic in order to stay small. However, when I tried to use it for my project which is fairly complex in extension terms (multiple platforms, 3 different dependent libraries and multithreading) it turned out to be much to simple. After spending far too much time trying to fix the various issues with mkrf I just went back to mkmf, read more of the code and some other extensions and got my stuff to work. Here’s a short laundry list of problems I ran into with mkrf:

  • Bug in non-supression of logging during test compile stage (using $debug rather than $DEBUG)
  • Logging was too minimal overall, it was not clear in mkrf what settings and source it was trying to compile without getting into the code.
  • Mkrf uses the wrong rbconfig settings for test compiles, the settings are not compatible on platforms other than the one it was written on. It should take a note from mkmf in this regard and use Config['TRY_COMPILE'] instead of Config['CC']
  • It was not possible without a hack to modify the library search path of @availability before test compiles were invoked. This is troublesome when you have cascading library dependencies.
  • Using rake is neat idea but it adds a seperate dependency to a project (albiet one that is easily resolved by rubyists who know how to install rake). I would like my extension to have as low a barrier to entry as posible to encourage non-ruby programmers to try it.
  • All standard extensions use mkmf and so you know that if they could compile ruby on their systems (which many systems can by this point), they can compile your extension.
My opinion is that currently (as of version 0.20) mkrf is an interesting idea that doesn’t yet close the gap for extension writers with more needs than compiling ‘libtrivial’ on whatever platform mkrf was written on. Compiling cross platform code is not trivial matter but for the most part mkmf does a great job of making it feel pretty trivial.

technorati tags:,

This entry was posted in ruby, rubycube. Bookmark the permalink.

2 Responses to mkmf versus mkrf round 1

  1. Kevin Clark says:

    Hi Jacob, This is a great post. I’ve been actively seeking things like this for a while. I’m going to make tickets for some of your issues as soon as I can. If we get most of those resolved, would you be willing to test the compile for us? Most of my issues with cross-compat is lack of availability on my end.

  2. Kevin Clark says:

    Also, my rbconfig doesn’t appear to have a ‘TRYCOMPILE’. It has a ‘TRYLINK’, but it’s empty. Can you tell me what OS/Arch you’re on?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>