From: "Rocky B." Date: 2012-11-26T11:35:09+09:00 Subject: Re: How to create a gem which conditionally compiles/installs a C extension? Rocky B. wrote in post #1086286: > Jon Forums wrote in post #1086252: >>> * 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 >> >> `Gem::Ext::ExtConfBuilder` makes this difficult by (incorrectly) >> assuming it should always run make after extconf.rb; you must create a >> Makefile (even if it's just a no-op stub) and have an activated make on >> your system. >> >> I recently had a similar idea (comined pure-ruby and native gem with >> build decision made at install time by extconf.rb) and briefly toyed >> with wrapping the extconf.rb with a Rakefile. The quick hack didn't >> work, and I haven't had time to swing back and dance with the little >> monster. >> >> https://github.com/jonforums/ffi-bogus >> >> Perhaps it just needs another set of eyes and a bit more time. That >> said, a Rakefile + extconf.rb solution is a kludge. The right solution >> is to find a clever way to make RubyGems more nimble and not break >> existing extconf.rb builds. > > Agreed. > > I couldn't see how to make it work either. So until something better > comes along I've gone with the bogus C extension approach when it is not > needed. > > See https://github.com/rocky/rb-threadframe/tree/master/ext > >> >> Jon Sigh. The gems have been released and my patience for gem hacking has worn very thin. Tell you what... fork the code, patch it and submit a merge request on github. Then I'll try it out in the various circumstances. One potential problem I see (as mentioned previously) is that if one goes from MRI 1.9.3 to 1.9.2 the extension won't be there and you'll get an error. Right now what happens is that the C extension checks the Ruby version and suggests reinstalling the gem. This is a slightly better failure message. But again, what's really needed here is more and better gem intelligence with regard to the version of Ruby that one is running. -- Posted via http://www.ruby-forum.com/.