installing C + Ruby extensions

  • Thread starter Gerardo Santana Gómez Garrido
  • Start date
G

Gerardo Santana Gómez Garrido

I'm using mkmf for building and installing a C extension. I'm also
providing a gem.

I'm thinking of reorganizing the code to extract those C bits that can
be coded in Ruby, and extend them in Ruby, while preserving a C core
that provides a Ruby interface for the libraries I'm linking to.

My problem is how should my source tree look and what tools and how
should I use to have both the Ruby and the C portion built and
installed in the appropriate places.

Preferrably avoiding rubygems, so that I don't force my users to have rubyg=
ems.

Which makes me ask: if rubygems will be included in Ruby 2.0, =BFwill it
be mandatory?, =BFwould it make sense not to make a gem for an
extension?
 
T

Tim Hunter

Gerardo said:
I'm using mkmf for building and installing a C extension. I'm also
providing a gem.

I'm thinking of reorganizing the code to extract those C bits that can
be coded in Ruby, and extend them in Ruby, while preserving a C core
that provides a Ruby interface for the libraries I'm linking to.

My problem is how should my source tree look and what tools and how
should I use to have both the Ruby and the C portion built and
installed in the appropriate places.

Preferrably avoiding rubygems, so that I don't force my users to have rubygems.

Which makes me ask: if rubygems will be included in Ruby 2.0, ¿will it
be mandatory?, ¿would it make sense not to make a gem for an
extension?

I use Minero Aoki's setup.rb (you can find it on the RAA) for RMagick.
The code is a bit opaque but it's robust and mature. The source/build
tree that setup uses is here:
http://i.loveruby.net/en/projects/setup/doc/devel.html. RubyGems works
well with setup.rb, and it's not hard to build a tar.gz version as well
as a gem.

I do not recommend avoiding RubyGems. Unless the typical consumer of
your extension is different from the mainstream of Ruby programmers, I
don't think it's going to be a problem "forcing" them to have RubyGems.
In my experience 99% of Rubyists use RubyGems and probably half of them
are not able to install an extension that is not supplied in the form of
a gem.

RubyGems is built in to 1.9.0. While I don't think its use will be
*mandantory* it seems very useful to supply your extension as a gem.
Since the main problem with RubyGems today is that people don't know to
require "rubygems" before requiring the gem, having RubyGems built in to
Ruby will be very nice indeed, both for us and for our users.
 
G

Gerardo Santana Gómez Garrido

Thanks Tim for your reply, it has been very helpful.

I have another question.

I have a C core. I'm already extending it in Ruby. There's C code that
could be moved to Ruby. Would I gain anything doing this?
 
T

Tim Hunter

Gerardo said:
Thanks Tim for your reply, it has been very helpful.

I have another question.

I have a C core. I'm already extending it in Ruby. There's C code that
could be moved to Ruby. Would I gain anything doing this?

I think so. Ruby code is portable (that is, you know it will run because
Ruby is already running) and easier to maintain than C code.

RMagick started life as 100% C but after almost a year of work I threw
all the code away. I started over using as much Ruby as possible and
never looked back.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top