2

I build a Ruby gem, which needs some C extension. This one - once compiled - is bound via Ruby FFI into the gem.

My setup: I use bundle for the gem scaffolding. Inside my gems folder I have a subfolder ext. This one includes a static Makefile, another subfolder source and an extconf.rb.

The source folder contains all .c and .h files.

The Makefile does not have to be created dynamically. If I call make clean && make in ext everything compiles, and the gem works as expected.

Now I give extconf.rb the following contents:

require 'mkmf'
require 'fileutils'

# Give it a name
extension_name = 'somename'

# The destination
dir_config extension_name

# Do the work
create_makefile extension_name

# Overwrite Makefile
FileUtils.cp 'Makefile.template', 'Makefile'

So I let mkmf create a Makefile first, and overwrite it afterwards by my static template. Stupid.

When I build my gem now via rake build and try to install it on another machine, the extension is not compiled.

Can anyone tell me, what I have to do in order to get the extension compiles automatically on install?

Nakilon
  • 34,866
  • 14
  • 107
  • 142
GeorgieF
  • 2,687
  • 5
  • 29
  • 43
  • 1
    Could you show contents of gemspec - how does it set `gem.extensions` (variable name may vary)? Also, do you get an error message? Part of reason to have dynamic makefile is to allow for things changing on target machine needing different details in Makefile. – Neil Slater Sep 12 '13 at 13:26
  • 1
    Thank you Neil, I did not know about extensions in gemspec. That solved the problem. – GeorgieF Sep 12 '13 at 13:37

1 Answers1

6

Thanks to the hint of Neil Slater the solution was simple: I did not have gem.extension in my gemspec file like so:

s.extensions    = %w[ext/extconf.rb]

For anyone who faces the same issue.

GeorgieF
  • 2,687
  • 5
  • 29
  • 43