Skip to content

Don't fail if there is no makefile, simply don't do anything.#8879

Merged
deivid-rodriguez merged 1 commit into
ruby:masterfrom
ioquatix:extconf-optional-makefile
Aug 11, 2025
Merged

Don't fail if there is no makefile, simply don't do anything.#8879
deivid-rodriguez merged 1 commit into
ruby:masterfrom
ioquatix:extconf-optional-makefile

Conversation

@ioquatix
Copy link
Copy Markdown
Member

@ioquatix ioquatix commented Jul 27, 2025

On some platforms, no native extensions should be created. This is typical for JRuby. Due to limitations in the extension builder, it is typical to create a dummy makefile that does nothing:

https://github.com/search?q=File.write+Makefile+path%3A**%2Fextconf.rb&type=code

This seems like a bad pattern.

  • It's not intentional: we are faking the creation of a makefile for the sake of "build" and "clean".
  • It's inefficient: make is still invoked several times even when no build steps are required.
  • It's difficult: gems with native extensions for JRuby have to jump through hoops in order to work.
  • It clutters the output: creating unnecessary files and artifacts.
  • It's confusing: it suggests a native build occurred when it didn't and makes debugging build issues harder.

I think it would be preferable to just do:

# extconf.rb

return if build_not_required?

require "mkmf"

...

create_makefile

Make sure the following tasks are checked

@ioquatix ioquatix force-pushed the extconf-optional-makefile branch from 75d17a1 to 480d641 Compare July 27, 2025 23:24
ioquatix added a commit to socketry/io-event that referenced this pull request Jul 27, 2025
ioquatix added a commit to socketry/io-event that referenced this pull request Jul 27, 2025
@ioquatix ioquatix force-pushed the extconf-optional-makefile branch from 480d641 to 4450cdb Compare July 27, 2025 23:46
@headius
Copy link
Copy Markdown
Contributor

headius commented Jul 28, 2025

I'm +1 for this of course. May also help #3520?

@ioquatix
Copy link
Copy Markdown
Member Author

I don't really understand the full issue here, but in order to support #3520 we'd probably need to communicate the fact that no native extension was built back to the index that's tracking what gems are compatible with what, if any such index exists.

@eregon
Copy link
Copy Markdown
Member

eregon commented Jul 29, 2025

LGTM as well, seems convenient and cleaner than a dummy makefile.

Copy link
Copy Markdown
Contributor

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

More work will be needed for #3520, but this is a good change and everyone agreed with it over at #7372 and https://bugs.ruby-lang.org/issues/20152.

The implementation seems fine to me, too 👍.

I'll leave this opened for a couple more days in case additional reviewers show up, but I'm good with this!

@ioquatix ioquatix force-pushed the extconf-optional-makefile branch from 4450cdb to 0e92346 Compare August 7, 2025 14:02
@deivid-rodriguez
Copy link
Copy Markdown
Contributor

Let's do this, thanks so much @ioquatix!

@deivid-rodriguez deivid-rodriguez merged commit 44e36f5 into ruby:master Aug 11, 2025
73 checks passed
@ioquatix ioquatix deleted the extconf-optional-makefile branch August 11, 2025 10:07
@eregon
Copy link
Copy Markdown
Member

eregon commented Feb 6, 2026

For convenience: this got in RubyGems 4.0.0 but not earlier versions.
That means this trick can only be used unconditionally in gems not supporting Ruby < 4.0.
For gems supporting Ruby 3.x they'll need to either use the dummy makefile approach unconditionally, or use a mix of both (return on RUBY_VERSION 4.0+, dummy makefile otherwise)

@fxn
Copy link
Copy Markdown
Contributor

fxn commented Feb 9, 2026

For a gem that has a portable Ruby implementation, but that may optionally optimize something in C if possible, would it make sense to ship a gemspec that defines spec.extensions depending on Gem::VERSION?

spec.extensions = ["ext/zeitwerk/extconf.rb"] if Gem::VERSION >= ...

Or could that break some assumption about gem contents in RubyGems somehow?

@eregon
Copy link
Copy Markdown
Member

eregon commented Feb 9, 2026

@fxn That does not work, because there is a single gemspec serialized to YAML/etc uploaded to rubygems.org and so that conditional is "lost" after publishing the gem.

@fxn fxn mentioned this pull request Feb 9, 2026
4 tasks
@fxn
Copy link
Copy Markdown
Contributor

fxn commented Feb 9, 2026

Thanks @eregon, I have written a doc patch for it: #9321.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants