Feature #15156
closedHave a 'c_headers' specifier in Gem::Specification.
Description
Currently if one Ruby gem depends on the C extension of another Ruby gem, the only way
find the header of that gem is to run a Gem::Specification.find_by_name
in the extconf.rb
of the gem needing the header and then adding the folder containing the header relative to
that path.
This approach is error-prone for three reasons:
- It relies on the gem developer to do the hard work of finding out exactly where the needed
header file is located inside the sources of the gem. - It assumes that the location of header file will never change irrespective of gem releases.
- The gem author then needs to re-dig the sources of the source gem to find where the header
is now located.
This is a considerable maintainence burden, especially given that there is no 'standard' way
of keeping public header files for C extensions of ruby gems.
I propose a new approach that will allow a gem developer to specify the path of the public
C header files in a new attribute within Gem::Specification
in the gemspec of the source
gem. Thus, if someone wants to use the public headers of a gem, they can simply add the
following lines to their extconf.rb
:
spec = Gem::Specification.find_by_name 'source-gem-name', 'source-gem-version'
find_header("source_gem.h", *spec.c_headers)
The way the source gem can specify the header file in their source-gem-name.gemspec
can
be like so:
Gem::Specification.new do |spec|
# lots of other specs
spec.c_headers = ["path/to/headers/1", "path/to/headers/2"]
end