[Rake-devel] Building native extensions with Rake

Luis Lavena luislavena at gmail.com
Tue Nov 18 14:55:47 EST 2008

On Tue, Nov 18, 2008 at 4:31 PM, Charlie Savage <cfis at savagexi.com> wrote:
> Hi Luis,
>> I'm working on a series of tasks that ease the compilation of Ruby C
>> Extensions with Rake. The goal of these tasks are ease the building
>> and compilation of Ruby C extensions, also looking into be
>> merged/integrated into Rake.
> I really like the idea, but I don't think this is the right way to do it.
>  The fundamental issue with building extensions is Ruby's assumption that
> the compiler used to build ruby itself is the same as the one used to build
> an extension.  On Windows, with MingW and VC++, that is often not the case.
>  Adding a few rake tasks doesn't solve the problem, so doesn't make anything
> any easier.

I agree with you, Ruby assumption is dumb, but you cannot build
extensions for current ruby with VC8, even going away of the compiler

The thing is that both libraries will depend on different CRT which at
the same time will alloc and release objects from their HEAP, mixing
CRTs in the same space will segfault. Been there, done that.

> In my view, the real solution is to port Python's DistUtils to Ruby and
> using it as the standard way of building ruby extensions.  Distutils takes a
> much more object oriented approach than mkmf, so is a lot more flexible.
>  This flexibility allows it to support multiple compilers, and from limited
> experience, it works quite well.

It works if the compiler used to build the language links to the same
runtime used by your extension, as I commented above.

The only one capable of doing that is MinGW, which you can opt for
which CRT you want your build link to.

> I don't know if the community would be interested in such a big change, but
> I think it would be a big leap forward for Ruby and extensions.

I tried to get people on this subject several times, all without luck.

The idea behind these tasks is provide a standard building mechanism
when using Rake, which will also open the door for doing cross
compilation (I have that in my stash of things to commit).

as example, I can do: rake cross compile to use gcc-mingw32 on Linux
to build things for Windows. what is missing is gem packaging (and of
course, specs).

Having a standard will allow projects simplify code and also let us
pursue other solutions in the background.

extconf.rb situation is something else, keep in mind that it just
generates the makefile, but my proposal is more abstract and has
nothing to do with compiler except for "make" or "nmake" on Windows.

Luis Lavena
Human beings, who are almost unique in having the ability to learn from
the experience of others, are also remarkable for their apparent
disinclination to do so.
Douglas Adams

More information about the Rake-devel mailing list