How can I determine if a ruby gem is actually a native C extension?
When running gem install some_gem
I can see when it tries to build the native extension, but is there a way to determine which of the gems are native C extensions before installing it?
You can check the gem specification to see if extensions
is defined. You have to download the gem or check its source to do this, but it's not to difficult to do programmatically with a bit of unix-fu:
curl -L <gem-url> | tar xOf - metadata.gz | gunzip | ruby -r yaml -e 'p YAML.load($stdin.read).extensions.any?'
Let's compare bson & bson_ext (since they're the first non-C-extension and C-extension versions of the same gem I could think of):
% curl -L https://rubygems.org/downloads/bson-1.8.0.gem | tar xOf - metadata.gz | gunzip | ruby -r yaml -e 'p YAML.load($stdin.read).extensions.any?'
false
% curl -L https://rubygems.org/downloads/bson_ext-1.8.0.gem | tar xOf - metadata.gz | gunzip | ruby -r yaml -e 'p YAML.load($stdin.read).extensions.any?'
true
You could automate the need to know the current version of the gem by using the RubyGems API:
curl https://rubygems.org/api/v1/gems/bson.yaml | ruby -r yaml -e 'p YAML.load($stdin.read)["version"]'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With