Reputation: 3334
I have a little project that I want to share via a gem. This extension must be compiled on the user system. So the compilation must be done when the gem is installed.
My project is simple:
tree
├── myext.gemspec
├── ext
│ └── myext
│ └── myext.c
│ └── extconf.rb
├── lib
│ ├── myext
│ └── myext.rb
├── Rakefile
└── test
I have checked the extconf.rb and the compilation works if I do
ruby extconf.rb && make
I have a myext.gemspec:
Gem::Specification.new do |s|
s.name = 'myext'
s.version = '0.0.1'
s.date = '2015-04-22'
s.summary = "an extension"
s.description = "an extension that is mine"
s.authors = ["cedlemo"]
require "rake" #for FileList
s.files = FileList['lib/*/*.{so}',
'lib/*.{rb}'
].to_a
s.extensions = %w(ext/myext/extconf.rb)
s.add_development_dependency 'rake-compiler', '~> 0'
s.license = 'MIT'
end
and here is my Rakefile :
require "rubygems"
require "rake/extensiontask"
spec = Gem::Specification.load('myext.gemspec')
Rake::ExtensionTask.new "myext", spec do |ext|
ext.lib_dir = "lib/myext"
end
When I build my gem, everything is fine :
gem build myext.gemspec
And when I install the gem I havn't any error message:
gem install myext-0.0.1.gem
Building native extensions. This could take a while...
Successfully installed myext-0.0.1
1 gem installed
My problem is that the C code is not compiled and I don't have any .so file installed:
/home/cedlemo/.gem/ruby/2.2.0/gems/myext-0.0.1/
├── ext
│ └── myext
│ ├── extconf.rb
│ └── Makefile
└── lib
└── myext.rb
PS: I have read a lot of documentations (official or blogs ...) and everybody is doing its own stuff so it is not very clear and I can't find a solution so don't send me link to http://guides.rubygems.org/ for example.
Upvotes: 1
Views: 808
Reputation: 79733
You haven’t included the source files in your files
part of your gemspec
, so there is nothing to compile when installing the gem. Make sure you include all needed files:
s.files = FileList['lib/**/*.rb', 'ext/**/*.{rb,c,h}']
You don’t need to include .so
files, as they will be built during installation (and might not actually be .so
). Also I don’t think you need to add to_a
(a FileList
basically is an array already).
Upvotes: 2