Erica
Erica

Reputation: 11

Packaging Ruby C extensions

I have found a blog about how to package Ruby C extensions

According to the blog ( http://blog.x-aeon.com/2012/11/28/packaging-ruby-c... ), it says

I have analyzed the Rhodes gem. This gem contains native extensions ( There is a file directory for the extensions, it has extconf.rb )

However, under the ext/ folder, there is no C source code. It only has makefile and shared library files ( so and dll ) with extconf.rb

This gem is platform independent. According to the gemfile, it says default to Ruby. It means it can run on any Ruby platform

If this is the case, this violates the rule 1: Add your C extension source files only: that is the .c and extconf.rb files only. No need for Makefile and compiled files for the Platform independent Ruby gems with native C extension case.

Do those rules always apply to any gemfile?

Also, would you able to explain "Add your compiled C extension files (exactly the same way you do for normal Ruby files)"?

Please help me out!

Upvotes: 1

Views: 480

Answers (2)

Douglas G. Allen
Douglas G. Allen

Reputation: 2261

By this time that page is dead. Your best bet is to look at some blogs by aka tenderlove.

Heres a link: https://tenderlovemaking.com/2009/12/18/writing-ruby-c-extensions-part-1.html

It sounds like this is laid out like what you described which I would say is the norm.

bin
ext
lib

In my experience it is best to have folders with the same names close to the gem extension name you want to build inside the ext and lib folders. And yes put the extconf.rb and your C files inside the sub folder of ext 'gem_ext_name'. But you may put things where ever you want as long as the Rakefile knows where they are.

My builds usually go into a tmp folder during compile and then when the shared object gets built it is copied out of the temp folder to the lib folder that has directories listed in the Rakefile to copy to.

Upvotes: 1

tadman
tadman

Reputation: 211600

It looks like rhodes is wildly cross-platform so this complicates things significantly. The plaftorm-specific code is stored in platform broken out by platform.

For a simple gem, you're right, the content should be in ext/. It looks like in this case that wasn't sufficiently flexible.

If you look in the files in ext/ there's a lot of crazy stuff going on, that's way beyond the default stub put in there when you make a C-extension gem.

Upvotes: 1

Related Questions