Bug #21792
closed4.0.0-preview3: Build fails with `--with-ext=` when ENABLE_SHARED=yes: ruby/digest.h not found for rubyspec CAPI extensions
Description
When building Ruby with --enable-shared and --with-ext= (empty, to disable all extensions), the build fails because spec/ruby/optional/capi/ext/digest_spec.c cannot find ruby/digest.h.
This affects cross-compilation tooling like rake-compiler which uses these configure options to build a minimal Ruby for cross-compiling native gems.
Reproducing¶
Download and extract ruby-4.0.0-preview2 source code.
cd ruby-4.0.0-preview2
./configure --enable-shared --disable-install-doc --with-ext=
make
Or alternatively, use rake-compiler:
mkdir ~/.rake-compiler
rake-compiler cross-ruby VERSION=4.0.0-preview2 HOST=x86_64-linux-gnu
Either way, you will see:
spec/ruby/optional/capi/ext/digest_spec.c:4:10: fatal error: ruby/digest.h: No such file or directory
4 | #include "ruby/digest.h"
| ^~~~~~~~~~~~~~~
compilation terminated.
make: *** [defs/gmake.mk:521: spec/ruby/optional/capi/ext/digest_spec.so] Error 1
Root Cause¶
I believe the root cause is:
- defs/gmake.mk:531-532 unconditionally adds rubyspec-capiext to the exts target when ENABLE_SHARED=yes:
ifeq ($(ENABLE_SHARED),yes)
exts: rubyspec-capiext
endif
- rubyspec-capiext builds all *.c files in spec/ruby/optional/capi/ext/, including digest_spec.c
- digest_spec.c (line 4) includes ruby/digest.h
- ruby/digest.h is only installed when the digest extension is built. From ext/digest/extconf.rb:7-9:
$INSTALLFILES = {
"digest.h" => "$(HDRDIR)"
} if $extmk
- With --with-ext= (empty), the digest extension is not built, so digest.h is never copied to .ext/include/ruby/
- The build fails because digest_spec.c requires a header that was never installed
Note that before 269ad29d, no rubyspec CAPI extension required extension-specific headers, so this configuration worked.
Updated by mdalessio (Mike Dalessio) 21 days ago
Note that this also reproduces in the source tree for 656de67d / 4.0.0-preview3.
Updated by mdalessio (Mike Dalessio) 21 days ago
- Subject changed from 4.0.0-preview2: Build fails with `--with-ext=` when ENABLE_SHARED=yes: ruby/digest.h not found for rubyspec CAPI extensions to 4.0.0-preview3: Build fails with `--with-ext=` when ENABLE_SHARED=yes: ruby/digest.h not found for rubyspec CAPI extensions
Updated by mdalessio (Mike Dalessio) 21 days ago
I've proposed a potential fix at https://github.com/ruby/ruby/pull/15617
Updated by nobu (Nobuyoshi Nakada) 20 days ago
I don't think the installation script works with no extensions because it loads rubygems that require monitor.
Updated by mdalessio (Mike Dalessio) 19 days ago
I don't think the installation script works with no extensions because it loads rubygems that require monitor
@nobu (Nobuyoshi Nakada) Is this something that changed since Ruby 3.4? rake-compiler has been using the --with-ext= (empty) option since 2015. I did a quick search but I could not find where this dependency was introduced.
Turning off extensions is an optimization (see the original commit https://github.com/rake-compiler/rake-compiler/commit/8ed7c2a6 for more context) so we can remove it, but I would like to make sure that this is an intentional decision in Ruby before proposing its removal in rake-compiler for building Ruby >= 4.0.
Updated by mdalessio (Mike Dalessio) 19 days ago
I don't think the installation script works with no extensions because it loads rubygems that require monitor
Is this something that changed since Ruby 3.4?
Ah, I see, is this because logger relies on monitor, and logger is no longer part of the stdlib (it is a bundled gem)?
Updated by nobu (Nobuyoshi Nakada) 19 days ago
mdalessio (Mike Dalessio) wrote in #note-6:
Ah, I see, is this because logger relies on monitor, and logger is no longer part of the stdlib (it is a bundled gem)?
Not logger, lib/rubygems/core_ext/kernel_require.rb requires monitor, to create RUBYGEMS_ACTIVATION_MONITOR.
Also date via time is used in rdoc.
Updated by Eregon (Benoit Daloze) 18 days ago
Do you then use this "minimal Ruby" to run the gem extconf.rb?
I don't think that works in general without extensions, extconf.rb can assume the full stdlib to be available.
As nobu said even RubyGems cannot load without monitor, a C extension (on CRuby).
Updated by Anonymous 18 days ago
- Status changed from Open to Closed
Applied in changeset git|e6520de3442659def3463d3bfdca3432f41b2d6a.
[Bug #21792] Build rubyspec-capiext only when excuting test-spec
rubyspec-capiext is only needed for running specs, not for building or
installing Ruby.