djberg96 ([info]djberg96) wrote,
@ 2009-08-07 11:04:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
Current location:United States, Colorado, Broomfield
Current mood: blah
Entry tags:ffi, ruby

FFI Blues
Lately I've been experimenting with FFI, the wrapper around libffi that let's you write C code without ever leaving pure Ruby. I figured with JRuby already using it, and Rubinius and IronRuby on their way, it might be time to start porting some of my C extensions over.

Unfortunately, I've slammed into the cold hard fact that FFI just isn't the grand solution we all hoped it would be. The first problem is that libffi, the underlying source for C based implementations, isn't going to build without the gcc toolchain. That pretty much leaves everyone but Linux, FreeBSD and OS X in the dust, including two heavy hitters, MS Windows and Solaris (if you're using the Sun Studio compiler). Then there's the issue of JRuby's lack of support for certain parts of C, such as file descriptors, as my attempt to port file-temp demonstrated.

So now I'm in a dilemma. If I want to write cross-platform code that will work with JRuby and C based implementations, I'm relegated to keeping two (or more) separate source files, one for MRI and one for JRuby. It would more likely be 3, as I'll still need a separate source file for Windows, since the code is radically different from its *nix counterpart most of the time.

On top of that I've heard disturbing reports that there is little interest in supporting FFI on Windows, in which case we may as well declare it dead in the water. Whether you like it or not, Windows is a major player and its here to stay. If it's not going to work on Windows you may as well chuck it now and stick with C extensions.




(3 comments) - (Post a new comment)


[info]thornik
2009-08-11 10:51 am UTC (link)
Heya, man! Interesting topic! Just now I'm fighting with ugly DBD-mysql module, which (I suppose) developed under Linux and cannot be compiled w/o magic on Windows.
If you be so kind, can you explain (good topic for post!) which ways exist for Ruby to use external libraries? I'm newbie and heard about FFI only, but many beginners need this info.
Thanks!

(Reply to this) (Thread)

Addition
[info]thornik
2009-08-11 10:55 am UTC (link)
I'm using VC 2008, but unsure what Ruby expected as a 'external library' - DLL? LIB? On Windows port of Ruby 1.9.1 I found strange .so files (with obviously not a 'shared library' of Linux) - what is it?

(Reply to this) (Parent)


[info]drbrain
2009-08-18 10:40 pm UTC (link)
C extension using mkmf.rb/extconf.rb

C extension using RubyInline

SWIG-generated C extension

DL (from the standard library)

FFI

(at least)

the first three require a compiler that matches the one ruby was built with. The last two do not an can work against the DLL itself without extra code.

(Reply to this) (Parent)


(3 comments) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…