[Rubygems-developers] Gem build process for C extension

Jeff Davis ruby at j-davis.com
Fri Jan 4 22:43:38 EST 2008

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

> > (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.

I would also suggest a mechanism to supply CFLAGS (perhaps I missed
it?). This is less important to me, however.

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.

	Jeff Davis

More information about the Rubygems-developers mailing list