Packaging Ruby C extensions

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

According to the blog (

), it says

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

  2. Add ext directory to the required paths

  3. Keep the platform as Ruby (independent)

  4. Register the C extensions you are including: this will tell RubyGems
    that there is a compilation step upon installation. This is done by
    giving all the paths to extconf.rb files.

  • Platform dependent Ruby gems with native C extension
  1. Add your compiled C extension files (exactly the same way you do for
    normal Ruby files)

  2. Add ext directory to the required paths

  3. Set the platform as current

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)”?

My guess is they do have some source, it’s just in a different place
[you’ll notice the extconf.rb files, etc. call out to some other
rakefiles, etc.]

seems to have at least some C source.
GL!

If you are looking for a simple rubygem with typical C extension, have a
look at rugged, libgit2 bindings in Ruby.

Rhodes is a huge and complex project, it is not suitable as a learning
example how to package C extensions for rubygems.