How do we find out if gems have native code?

Hello,

I have a question about native extension code.
I want to find if the gem is written with some extension code.

For the Ruby, it seems like if there is an ext folder under the gem
folder, it has native code.

For example, for the nokogiri and json gem, we can find native C code
under the ext folder.

In the gemfile, if it contains “extensions” line, it seems like it has
native extension in the gem.

I started wondering if there can be native extension code located other
than ext folder.

Are all the native extension code located under the ext folder?
Does gem with extensions always have extconf.rb?

Also, if we look at the rake gem, there is a folder called examples. It
contains some .c files.

I am not sure if the rake gem contains native C extensions.

Is there a way to find out if the gem contains native extensions?

Thank you so much!

Erica Kim wrote in post #1157749:

Hello,

I have a question about native extension code.
I want to find if the gem is written with some extension code.

There is no subcommand for gem command to detect whether a remote
rubygem has some extension present. You need to look at the source code
of the rubygem. The command gem search YOUR_GEM -d might be helpful
here.

However, once you have a gem installed you can use the command gem specification which outputs a very detailed spec for the gem in yaml
format.

For the Ruby, it seems like if there is an ext folder under the gem
folder, it has native code.

It’s described in the rubygems guide, see here:

Are all the native extension code located under the ext folder?
Does gem with extensions always have extconf.rb?

It’s the convention, the guide says: The files for the extension should
go in the ext/ directory in a directory matching the extension’s name.

Also, if we look at the rake gem, there is a folder called examples. It
contains some .c files.

Those file (located here
rake/doc/example at master · ruby/rake · GitHub) are there only to
be useful in the example Rakefiles. Look into the Rakefile1 and
Rakefile2 to see more.

I am not sure if the rake gem contains native C extensions.

Rake has no native extensions.

Is there a way to find out if the gem contains native extensions?

As mentioned above: gem specification SOME_GEM
You need however to get this gem installed locally before using that.

v.