[Rubygems-developers] Gem build process for C extension

Luis Lavena luislavena at gmail.com
Fri Jan 4 22:57:57 EST 2008

On Jan 5, 2008 1:43 AM, Jeff Davis <ruby at j-davis.com> wrote:
> On Fri, 2008-01-04 at 18:54 -0800, Kevin Clark wrote:
> > > (a) How do I tell rubygems to invoke "rake" rather than "make" during
> > > the build process? I assume I just need to put something in
> > > the .gemspec, but I don't know what.
> >
> > If you have a Rakefile or a mkrf_config in the ext directory, it
> > should use those instead of an extconf.
> Doesn't extconf.rb (using mkrf) generate the Rakefile? I don't bundle a
> Makefile or a Rakefile. After extconf.rb is run, the Rakefile is
> perfect, but I don't think "gem install" is running "rake", because it
> fails.

I actually don't know about mkrf, but I think you should use
mkrf_config.rb instead of extconf.rb to name the "builder" script.

Anyway, I don't haver personal experience with that or the capacity of
rubygems to handle mkrf.

> > > (b) How do I tell rubygems that my gem now has a dependency on the
> > > "mkrf" gem?
> >
> > Just add mkrf as a dependency like you would with other gems.
> Is there some documentation about the .gemspec? This is new territory
> for me.


> > > Are there documents or examples showing how to properly use gems in
> > > conjunction with a C extension and its build process? How do other
> > > people make sure path names are quoted properly? Should I use mkmf or
> > > mkrf?
> >
> > There's an example in the Pickaxe, and one here
> > http://www.tarkblog.org/rubyextension
> >
> > I can't speak to quoting pathnames. I'd say mkrf is probably a better
> > starting point if _any_ hacking is to be done. I've quarantined the
> > part of my brain that understood mkmf for fear the disease would
> > spread. It isn't as widely used though, so there may be things
> > missing. Please _do_ file bug reports if that's the case.
> >
> I agree completely that mkrf is a better starting point. All I had to do
> was quote the include paths (mkmf made this more difficult by supplying
> quotes for some paths and not others, and changing between versions...).
> I would suggest that user-supplied data be quoted appropriately from
> mkrf (rather than the calling code), such that an include or lib dir
> with spaces (or some other strangeness) be automatically made safe for
> inclusion in the shell commands.

On what platform are you? since is not impossible but uncommon find
paths with spaces under *nix.

> Making it easier to write extensions for Ruby helps everyone, and mkrf
> looks like the right way to do that. Thanks for working on it.

Last time I tried to look at mkrf, couldn't get an updated repository
por point of contact for the project (code was dated 2006 and never

Luis Lavena
Multimedia systems
A common mistake that people make when trying to design
something completely foolproof is to underestimate
the ingenuity of complete fools.
Douglas Adams

More information about the Rubygems-developers mailing list