From: "Rocky B." Date: 2012-11-25T08:37:31+09:00 Subject: How to create a gem which conditionally compiles/installs a C extension? I have a gem that needs to compile and install a C extension on MRI 1.9.2. But on MRI 1.9.3 it doesn't. What's the best way to accomplish this? Here are some possibilities and the ramifications of them. * Create the gem in such a way to distinguish MRI 1.9.3 versus MRI 1.9.2. I think this would be the cleanest, but I don't think this is possible. Were this possible, in the gemspec one could put something add like: Gem::Specification.new do |spec| spec.extensions = ['ext/extconf.rb'] if '1.9.2' == RUBY_VERSION ... * Create a bogus extension for 1.9.3. This forces users to have a C compiler installed when it's really not needed. This also has the possibly weird effect that if the gem was originally built for 1.9.3 and one goes back to 1.9.2 and that extension is around and gems are shared across 1.9.3 and 1.9.2 then this breaks. (The more expected direction of building on 1.9.2 and upgrading to 1.9.3 would work however because on 1.9.3 the code doesn't try to load the extension). Perhaps this is too much of an edge case to be concerned about. * Figure out some way in the gem to dynamically disable compiling the extension on MRI 1.9.3. For example in ext/extconf.rb: if '1.9.2' == RUBY_VERSION create_makefile(...) else ??? end Thoughts and comments? -- Posted via http://www.ruby-forum.com/.