From: "headius (Charles Nutter) via ruby-core" Date: 2024-01-24T06:18:02+00:00 Subject: [ruby-core:116392] [Ruby master Feature#20152] mkmf / extconf: Add a proper way to not compile the extension Issue #20152 has been updated by headius (Charles Nutter). Finally jumping in here. I think this was initiated by me filing an issue on erb to move the C extension out to a separate gem. Background: JRuby users traditionally have not needed any build tools **whatsoever** to install JRuby and build and run Rails applications. Everything is pre-built for JVM (though that has changed a bit with sassc). As it existed a few versions ago, the erb gem would unconditionally try to build the C extension it ships with, which meant that JRuby users could not install it. The first fix was to just emit a dummy Makefile on JRuby, which only half fixes it; JRuby users would still have to have `make` installed, even though the build would produce **nothing at all**. Let's be honest, the empty-Makefile trick is a hack at best. There should be a way in RubyGems to indicate that the current OS, OS version, ARCH, RUBY_ENGINE, RUBY_VERSION, etc does not need an extension built, so don't try to build it. That obviously applies in this case (Ruby fallback works fine), but it also applies to any gems that want to ship pre-built native libraries with more customization than just OS and ARCH. I don't have a strong opinion on "skip dummy makefiles" vs "don't try to build" but the former would integrate more easily. There *are* places where we accept that `make` will be needed, like sassc (to build the native library bound in Ruby using FFI), and we would not want to disable `make` for all gems. We just want to fix the ones that really don't need to build, like erb. ---------------------------------------- Feature #20152: mkmf / extconf: Add a proper way to not compile the extension https://bugs.ruby-lang.org/issues/20152#change-106415 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal ---------------------------------------- ### Context There are various gems that ship with a native extension as a way to speedup part of the gem, but also ship with a pure Ruby version of these methods as a fallback. So they only want to compile the extension if the platform supports it, and if not, just fallback to the slightly slower Ruby version. Right now users rely on one of two hacks to do this. Either they create an empty Makefile, but then still depend on `make` being available, or publish platform specific packages without any extension in them. Examples: - [`bootsnap` skip compilation if not on MRI or TruffleRuby](https://github.com/Shopify/bootsnap/blob/070151f1305f23102365d6b4476a91c02dead35a/ext/bootsnap/extconf.rb) - [`erb` has an extension for MRI but then need to publish a `java` version of the gem that doesn't actually contain Java code, just to skip compilation on JRuby](https://github.com/ruby/erb/issues/52) - [`hiredis-client` skips the compilation for Windows and non-MRI rubies](https://github.com/redis-rb/redis-client/blob/1ab081c1d0e47df5d55e011c9390c70b2eef6731/hiredis-client/ext/redis_client/hiredis/extconf.rb#L10-L17) ### Feature It would be very useful to have some proper first class API to skip compiling the extension. Something like: ```ruby require "mkmf" if RUBY_ENGINE != "ruby" || RUBY_PLATFORM.match?(/mswin/) skip_compilation else # ... end ``` cc @k0kubun @headius -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/