[Rubygems-developers] Native Extensions and Pure Ruby Alternatives (again)

Luis Lavena luislavena at gmail.com
Fri Nov 30 00:29:44 EST 2007


On Nov 29, 2007 11:39 PM, Trans <transfire at gmail.com> wrote:
>
> Welll. I have it. Its quite simple. This is how it works: if you set
> 'extensions_fallback' to true in the gemspec and an extension fails to
> build on install then it says "Native extension failed to compile, but
> this gem has a fallback option. Would you like to complete the install
> without the native extensions or abort? [Y/n]
>
> If the RubyGems team thinks this is acceptable I'll send it their
> way... Honestly, I don't know how else it can be done. Without this
> one is stuck with maintaning a secondary gem and trying to inform
> potential users that there is a pure ruby option in case the native
> extension one fails --but maybe that's what the RubyGems team
> considers the better approach?
>

I don't consider that a good approach:

A) If you create a product (a gem) that couldn't exist without the
native extension, you should try to provide the gem as pure ruby
(Gem::Platform::RUBY) and state in the gem requirements "this gems
need a compiler".

Also, is possible to create gems with the extensions compiled for a
specific platform, like we do for Mongrel gem, that will allow the
user choose the best one for his case.

B) If you create a product (a gem) that can exist without the native
extension (being the native extension a enhancement in performance or
functionality) offer the pure ruby version as the basic one, and the
native extension in a similar fashion as I stated before, but maintain
it as another gem.

Then you put in your code a try/catch block to look for the "enhanced"
version and fallback to the pure ruby one.

In that way, you don't need to mess with gem specifications which
could render the gems you create incompatible with the "standard"
until your changes are merged and slip into mainstream.

Of course, this is my point of view after been using rubygems a lot
for Mongrel, creating gems also for applications and tools on Linux,
Windows and FreeBSD.

-- 
Luis Lavena
Multimedia systems
-
Leaders are made, they are not born. They are made by hard effort,
which is the price which all of us must pay to achieve any goal that
is worthwhile.
Vince Lombardi


More information about the Rubygems-developers mailing list