On the FFI wiki there's a nice list of reasons why you should use FFI. That's the foreign function interface for Ruby. I imagine other languages have some similar facility
( Read more... )
That was a great articleext_236047June 3 2010, 03:26:07 UTC
You have a lot of good points! I've had issues with plugins that use FFI on solaris, and it is extremely frustrating having to deal with these cross-compatibility issues. Good job, once again!
I've run in to pretty much all of these problems. It sucks. Problems like these make developing with FFI an incredible pain.
Even worse is I think you've missed a few problems:
1. Struct layouts differ not only per platform but *per version* of a particular library too! That means you have to do platform *and* version detection.
2. Since the extension isn't compiled, you can't do feature detection using the preprocessor. Many libraries will define preprocessor macros so that you can detect which functions it makes available. With FFI, you have to find some sort of test you can perform at runtime.
3. Even if you make your extension work on all those ruby platforms, it *still* won't work on Google App Engine or Android.
I definitely think FFI has it's place. It is a good tool to have in the toolbox. But it is not the cross implementation savior it's been billed as.
1. Actually I did mention the per version issue. But, yeah, that's going to be a pain. Not that it's not a pain with C extensions, but it's going to be worse with FFI.
2. That was actually the motivation for mkmf-lite. Mind you, it still requires a C compiler on your system.
3. I'm not familiar with either platform, but thanks for the info.
Agreed, having FFI is certainly a good thing. It's certainly better than nothing!
Comments 6
Reply
Reply
Even worse is I think you've missed a few problems:
1. Struct layouts differ not only per platform but *per version* of a particular library too! That means you have to do platform *and* version detection.
2. Since the extension isn't compiled, you can't do feature detection using the preprocessor. Many libraries will define preprocessor macros so that you can detect which functions it makes available. With FFI, you have to find some sort of test you can perform at runtime.
3. Even if you make your extension work on all those ruby platforms, it *still* won't work on Google App Engine or Android.
I definitely think FFI has it's place. It is a good tool to have in the toolbox. But it is not the cross implementation savior it's been billed as.
Reply
2. That was actually the motivation for mkmf-lite. Mind you, it still requires a C compiler on your system.
3. I'm not familiar with either platform, but thanks for the info.
Agreed, having FFI is certainly a good thing. It's certainly better than nothing!
Reply
I just successfully compiled libffi using clang (from the LLVM project). So libffi isn't in that horrible of a state.
Dynamic struct layout detection would be *awesome*.
Reply
Reply
Leave a comment