Why does gem not auto compile my C extension

371 views Asked by At

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?

1

There are 1 answers

0
GeorgieF On

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.