Bug #19239
closedminiruby is not built by default when cross-compiling ruby 3.2.0-rc1
Description
When cross-compiling Ruby for darwin, the default make target doesn't build miniruby, even though it's needed for symbol resolution since https://github.com/ruby/ruby/commit/50d81bf
A workaround is to run make miniruby && make but I'm opening this issue to discuss if something needs to be fixed.
Here is a dockerfile that reproduces the issue:
FROM larskanis/rake-compiler-dock-mri-x86_64-darwin:1.2.2 RUN wget https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.0-rc1.tar.gz RUN tar -zxf ruby-3.2.0-rc1.tar.gz ENV DEBIAN_FRONTEND noninteractive RUN apt-get -y update && \ apt-get install -y curl git-core xz-utils build-essential zlib1g-dev libreadline-dev libssl-dev wget unzip sudo gnupg2 dirmngr cmake pkg-config autoconf libyaml-dev ENV CC x86_64-apple-darwin-clang RUN bash -c " \ rvm use 3.1.0 && \ cd ruby-3.2.0-rc1 && \ ./configure \ --host=x86_64-apple-darwin \ --target=x86_64-apple-darwin \ --build=x86_64-pc-linux-gnu \ --disable-jit-support \ " RUN bash -c " \ rvm use 3.1.0 && \ cd ruby-3.2.0-rc1 && \ make V=1 \ " Failure emits errors like this:
x86_64-apple-darwin-clang -dynamic -bundle -o ../../../.ext/x86_64-darwin/-test-/RUBY_ALIGNOF.bundle c.o cpp.o -L. -L../../.. -L. -fstack-protector-strong -Wl,-multiply_defined,suppress -Wl,-undefined,dynamic_lookup -bundle_loader '../../../miniruby' -lpthread ld: file not found: ../../../miniruby clang: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: Leaving directory '/ruby-3.2.0-rc1/ext/-test-/RUBY_ALIGNOF' make[2]: *** [Makefile:271: ../../../.ext/x86_64-darwin/-test-/RUBY_ALIGNOF.bundle] Error 1 make[1]: Leaving directory '/ruby-3.2.0-rc1' make[1]: *** [exts.mk:100: ext/-test-/RUBY_ALIGNOF/all] Error 2 make: *** [uncommon.mk:330: build-ext] Error 2 The error stems from the LD flag -bundle_loader '$(BUILTRUBY)' which points at miniruby, even though miniruby has not been built.
Replacing the last command with this will successfully build Ruby:
RUN bash -c " \ rvm use 3.1.0 && \ cd ruby-3.2.0-rc1 && \ make miniruby V=1 && \ make V=1 \ " This is also happening on master HEAD.
cc @katei (Yuta Saito) and @alanwu (Alan Wu) who seem to be familiar with the bundle_loader functionality.
Updated by mdalessio (Mike Dalessio) almost 3 years ago
@alanwu (Alan Wu) suggested the following patch, which I've submitted as a PR at https://github.com/ruby/ruby/pull/6944 :
diff --git a/common.mk b/common.mk index fbeccf8..4d4ba6d 100644 --- a/common.mk +++ b/common.mk @@ -327,7 +327,7 @@ ext/configure-ext.mk: $(PREP) all-incs $(MKFILES) $(RBCONFIG) $(LIBRUBY) \ configure-ext: $(EXTS_MK) -build-ext: $(EXTS_MK) +build-ext: $(EXTS_MK) miniruby$(EXEEXT) $(Q)$(MAKE) -f $(EXTS_MK) $(mflags) libdir="$(libdir)" LIBRUBY_EXTS=$(LIBRUBY_EXTS) \ EXTENCS="$(ENCOBJS)" MINIRUBY="$(MINIRUBY)" UPDATE_LIBRARIES=no $(EXTSTATIC) $(Q)$(MAKE) $(EXTS_NOTE)
Updated by nobu (Nobuyoshi Nakada) almost 3 years ago
Since it is macOS and disable_shared specific, I think the dependency can be in default/gmake.mk.
Updated by mdalessio (Mike Dalessio) almost 3 years ago
Thank you. I've updated https://github.com/ruby/ruby/pull/6944 with this patch:
diff --git a/defs/gmake.mk b/defs/gmake.mk index dc9d31f..9d27505 100644 --- a/defs/gmake.mk +++ b/defs/gmake.mk @@ -472,6 +472,8 @@ rubyspec-capiext: $(patsubst %.c,$(RUBYSPEC_CAPIEXT)/%.$(DLEXT),$(notdir $(wildc ifeq ($(ENABLE_SHARED),yes) exts: rubyspec-capiext +else ($(filter darwin%,$(target_os)),) +exts: miniruby$(EXEEXT) endif spec/%/ spec/%_spec.rb: programs exts PHONY
Updated by mdalessio (Mike Dalessio) almost 3 years ago
Final patch thanks to @nobu (Nobuyoshi Nakada) and @katei (Yuta Saito) is at https://github.com/ruby/ruby/pull/6959
Updated by nobu (Nobuyoshi Nakada) almost 3 years ago
- Status changed from Open to Closed