rbs icon indicating copy to clipboard operation
rbs copied to clipboard

rbenv install 3.1.0 fails at RBS Extension on Apple M1

Open solaris007 opened this issue 3 years ago • 15 comments

System:

➜ uname -a
Darwin <hostname> 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:29:10 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T8101 arm64

➜ rbenv -v
rbenv 1.2.0

➜ brew info ruby-build
ruby-build: stable 20211227 (bottled), HEAD

Action:

➜ rbenv install 3.1.0
Downloading openssl-1.1.1l.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/0b7a3e5e59c34827fe0c3a74b7ec8baef302b98fa80088d7f9153aa16fa76bd1
Installing openssl-1.1.1l...
Installed openssl-1.1.1l to /Users/dj/.rbenv/versions/3.1.0

Downloading ruby-3.1.0.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0.tar.gz
Installing ruby-3.1.0...
ruby-build: using readline from homebrew

BUILD FAILED (macOS 12.1 using ruby-build 20211227)

Inspect or clean up the working tree at /var/folders/yj/sb3sgyjj6zdgg6nmcjmg96gh0000gn/T/ruby-build.20220124065532.81312.5ymTIL
Results logged to /var/folders/yj/sb3sgyjj6zdgg6nmcjmg96gh0000gn/T/ruby-build.20220124065532.81312.log

Last 10 log lines:
	from ./tool/rbinstall.rb:899:in `block in install'
	from ./tool/rbinstall.rb:713:in `no_write'
	from ./tool/rbinstall.rb:899:in `install'
	from ./tool/rbinstall.rb:1068:in `block (2 levels) in <main>'
	from ./tool/rbinstall.rb:1043:in `foreach'
	from ./tool/rbinstall.rb:1043:in `block in <main>'
	from ./tool/rbinstall.rb:1127:in `block in <main>'
	from ./tool/rbinstall.rb:1124:in `each'
	from ./tool/rbinstall.rb:1124:in `<main>'
make: *** [do-install-all] Error 1

Result from log:

generating arm64-darwin21-fake.rb
arm64-darwin21-fake.rb updated
./miniruby -I./lib -I. -I.ext/common  ./tool/runruby.rb --extout=.ext  -- --disable-gems -r./arm64-darwin21-fake ./tool/rbinstall.rb --make="make" --dest-dir="" --extout=".ext" --ext-build-dir="./ext" --mflags="" --make-flags="" --data-mode=0644 --prog-mode=0755 --installed-list .installed.list --mantype="doc"  --gnumake --install=all --rdoc-output=".ext/rdoc" --html-output=".ext/html"
installing binary commands:         /Users/some-user/.rbenv/versions/3.1.0/bin
installing base libraries:          /Users/some-user/.rbenv/versions/3.1.0/lib
installing arch files:              /Users/some-user/.rbenv/versions/3.1.0/lib/ruby/3.1.0/arm64-darwin21
installing pkgconfig data:          /Users/some-user/.rbenv/versions/3.1.0/lib/pkgconfig
installing extension objects:       /Users/some-user/.rbenv/versions/3.1.0/lib/ruby/3.1.0/arm64-darwin21
installing extension objects:       /Users/some-user/.rbenv/versions/3.1.0/lib/ruby/site_ruby/3.1.0/arm64-darwin21
installing extension objects:       /Users/some-user/.rbenv/versions/3.1.0/lib/ruby/vendor_ruby/3.1.0/arm64-darwin21
installing extension headers:       /Users/some-user/.rbenv/versions/3.1.0/include/ruby-3.1.0/arm64-darwin21
installing extension scripts:       /Users/some-user/.rbenv/versions/3.1.0/lib/ruby/3.1.0
installing extension scripts:       /Users/some-user/.rbenv/versions/3.1.0/lib/ruby/site_ruby/3.1.0
installing extension scripts:       /Users/some-user/.rbenv/versions/3.1.0/lib/ruby/vendor_ruby/3.1.0
installing extension headers:       /Users/some-user/.rbenv/versions/3.1.0/include/ruby-3.1.0/ruby
installing rdoc:                    /Users/some-user/.rbenv/versions/3.1.0/share/ri/3.1.0/system
installing html-docs:               /Users/some-user/.rbenv/versions/3.1.0/share/doc/ruby
installing capi-docs:               /Users/some-user/.rbenv/versions/3.1.0/share/doc/ruby
installing command scripts:         /Users/some-user/.rbenv/versions/3.1.0/bin
installing library scripts:         /Users/some-user/.rbenv/versions/3.1.0/lib/ruby/3.1.0
installing common headers:          /Users/some-user/.rbenv/versions/3.1.0/include/ruby-3.1.0
installing manpages:                /Users/some-user/.rbenv/versions/3.1.0/share/man/man1
installing default gems from lib:   /Users/some-user/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0
                                    abbrev 0.1.0
                                    base64 0.1.1
                                    benchmark 0.2.0
                                    bundler 2.3.3
                                    cgi 0.3.1
                                    csv 3.2.2
                                    delegate 0.2.0
                                    did_you_mean 1.6.1
                                    drb 2.1.0
                                    english 0.7.1
                                    erb 2.2.3
                                    error_highlight 0.3.0
                                    fileutils 1.6.0
                                    find 0.1.1
                                    forwardable 1.3.2
                                    getoptlong 0.1.1
                                    ipaddr 1.2.3
                                    irb 1.4.1
                                    logger 1.5.0
                                    mutex_m 0.1.1
                                    net-http 0.2.0
                                    net-protocol 0.1.2
                                    observer 0.1.1
                                    open-uri 0.2.0
                                    open3 0.1.1
                                    optparse 0.2.0
                                    ostruct 0.5.2
                                    pp 0.3.0
                                    prettyprint 0.1.1
                                    pstore 0.1.1
                                    racc 1.6.0
                                    rdoc 6.4.0
                                    readline 0.0.3
                                    reline 0.3.0
                                    resolv 0.2.1
                                    resolv-replace 0.1.0
                                    rinda 0.1.1
                                    ruby2_keywords 0.0.5
                                    securerandom 0.1.1
                                    set 1.0.2
                                    shellwords 0.1.0
                                    singleton 0.1.1
                                    tempfile 0.1.2
                                    time 0.2.0
                                    timeout 0.2.0
                                    tmpdir 0.1.2
                                    tsort 0.1.0
                                    un 0.2.0
                                    uri 0.11.0
                                    weakref 0.1.1
                                    yaml 0.2.0
installing default gems from ext:   /Users/some-user/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0
                                    bigdecimal 3.1.1
                                    date 3.2.2
                                    digest 3.1.0
                                    etc 1.3.0
                                    fcntl 1.0.1
                                    fiddle 1.1.0
                                    io-console 0.5.10
                                    io-nonblock 0.1.0
                                    io-wait 0.2.1
                                    json 2.6.1
                                    nkf 0.1.1
                                    openssl 3.0.0
                                    pathname 0.2.0
                                    psych 4.0.3
                                    readline-ext 0.1.4
                                    stringio 3.0.1
                                    strscan 3.0.1
                                    syslog 0.1.0
                                    zlib 2.1.1
installing bundled gems:            /Users/some-user/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0
                                    minitest 5.15.0
                                    power_assert 2.0.1
                                    rake 13.0.6
                                    test-unit 3.5.3
                                    rexml 3.2.5
                                    rss 0.2.9
                                    net-ftp 0.1.3
                                    net-imap 0.2.2
                                    net-pop 0.1.1
                                    net-smtp 0.3.1
                                    matrix 0.4.2
                                    prime 0.1.2
                                    rbs 2.0.0
Building native extensions. This could take a while...
/private/var/folders/yj/sb3sgyjj6zdgg6nmcjmg96gh0000gn/T/ruby-build.20220124065532.81312.5ymTIL/ruby-3.1.0/lib/rubygems/ext/builder.rb:95:in `run': ERROR: Failed to build gem native extension. (Gem::Ext::BuildError)

    current directory: /Users/some-user/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/rbs-2.0.0/ext/rbs_extension
/Users/some-user/.rbenv/versions/3.1.0/bin/ruby --disable\\=gems -I/Users/some-user/.rbenv/versions/3.1.0/lib/ruby/3.1.0/arm64-darwin21 -I /private/var/folders/yj/sb3sgyjj6zdgg6nmcjmg96gh0000gn/T/ruby-build.20220124065532.81312.5ymTIL/ruby-3.1.0/lib -r ./siteconf20220124-54637-7a0x6j.rb extconf.rb
creating Makefile

current directory: /Users/some-user/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/rbs-2.0.0/ext/rbs_extension
make DESTDIR\\= clean
dyld[54642]: terminating because inserted dylib '/private/var/folders/yj/sb3sgyjj6zdgg6nmcjmg96gh0000gn/T/ruby-build.20220124065532.81312.5ymTIL/ruby-3.1.0/libruby.3.1.dylib' could not be loaded: tried: '/private/var/folders/yj/sb3sgyjj6zdgg6nmcjmg96gh0000gn/T/ruby-build.20220124065532.81312.5ymTIL/ruby-3.1.0/libruby.3.1.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'arm64e'))
dyld[54642]: tried: '/private/var/folders/yj/sb3sgyjj6zdgg6nmcjmg96gh0000gn/T/ruby-build.20220124065532.81312.5ymTIL/ruby-3.1.0/libruby.3.1.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'arm64e'))

current directory: /Users/some-user/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/rbs-2.0.0/ext/rbs_extension
make DESTDIR\\=
dyld[54643]: terminating because inserted dylib '/private/var/folders/yj/sb3sgyjj6zdgg6nmcjmg96gh0000gn/T/ruby-build.20220124065532.81312.5ymTIL/ruby-3.1.0/libruby.3.1.dylib' could not be loaded: tried: '/private/var/folders/yj/sb3sgyjj6zdgg6nmcjmg96gh0000gn/T/ruby-build.20220124065532.81312.5ymTIL/ruby-3.1.0/libruby.3.1.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'arm64e'))
dyld[54643]: tried: '/private/var/folders/yj/sb3sgyjj6zdgg6nmcjmg96gh0000gn/T/ruby-build.20220124065532.81312.5ymTIL/ruby-3.1.0/libruby.3.1.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'arm64e'))

make failed, uncaught signal 6

solaris007 avatar Jan 24 '22 06:01 solaris007

Looks like the ruby 3.1 is being built for arm64, but arm64e dylib is required. I don't know how this can happen...

I tried on my M1 MacBook Air, but it successfully installed 3.1.0 with RBS. It compiled arm64 ruby. I found /usr/bin/ruby is universal.arm64e-darwin21. There may be some confusion with it?

soutaro avatar Jan 27 '22 01:01 soutaro

I was able to install ruby 3.0.3, which features rbs-1.4.0, without a problem. ruby 3.1.0 uses rbs-2.0.0 - so there must definitely be a difference to earlier versions that break compilation.

rbenv correctly builds libruby.3.1.dylib as arm64 native, whereas for some reason rbs extconf.rb wants arm64e in rbs-2.0.0 but not 1.4.0

kindly check :)

solaris007 avatar Jan 27 '22 05:01 solaris007

@solaris007

How about installing from a tarball downloaded from https://www.ruby-lang.org?

$ curl -O https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0.tar.gz
$ tar xvf ruby-3.1.0.tar.gz
$ cd ruby-3.1.0
$ configure --prefix=/tmp/ruby-3.1  # Specify --prefix to avoid installing the ruby to /usr/local
$ make
$ make install                      # `make install` builds and installs the bundled gems including rbs

soutaro avatar Feb 02 '22 12:02 soutaro

yep, that works, i used:

$ ./configure --prefix=/tmp/ruby --with-openssl-dir="/opt/homebrew/opt/[email protected]"

solaris007 avatar Feb 02 '22 13:02 solaris007

Thanks. Great to hear it worked.

Hmm, I have no idea to do for this issue. It would be a problem of ruby-build or rbenv, or maybe homebrew?

soutaro avatar Feb 03 '22 00:02 soutaro

Hi, ruby-build maintainer's here.

I could install Ruby 3.1.0 with M1 macOS.

hsbt avatar Feb 03 '22 00:02 hsbt

Attached you'll find the diff between successful (right side) and failed ruby builds (left side). I see that ruby-build enables shared libs, whereas the manual build does not. I am no expert here, maybe you see something in the diff

ruby-build-diff.txt ruby-build-fail.txt ruby-build-success.txt

solaris007 avatar Feb 03 '22 05:02 solaris007

I think the issue is with make.

- ./miniruby -I./lib -I. -I.ext/common  ./tool/runruby.rb --extout=.ext  -- --disable-gems -r./arm64-darwin21-fake ./tool/rbinstall.rb --make="make" --dest-dir="" --extout=".ext" --ext-build-dir="./ext" --mflags="" --make-flags="" --data-mode=0644 --prog-mode=0755 --installed-list .installed.list --mantype="doc"  --gnumake --install=all --rdoc-output=".ext/rdoc" --html-output=".ext/html"

+ ./miniruby -I./lib -I. -I.ext/common  ./tool/runruby.rb --extout=.ext  -- --disable-gems -r./arm64-darwin21-fake ./tool/rbinstall.rb --make="/Applications/Xcode.app/Contents/Developer/usr/bin/make" --dest-dir="" --extout=".ext" --ext-build-dir="./ext" --mflags="" --make-flags="" --data-mode=0644 --prog-mode=0755 --installed-list .installed.list --mantype="doc"  --gnumake --install=all --rdoc-output=".ext/rdoc" --html-output=".ext/html"

Notice ruby-build uses the shell's make, and the manual build specifies the abs path.

$ file /Applications/Xcode.app/Contents/Developer/usr/bin/make
/Applications/Xcode.app/Contents/Developer/usr/bin/make: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64:Mach-O 64-bit executable arm64]
/Applications/Xcode.app/Contents/Developer/usr/bin/make (for architecture x86_64):	Mach-O 64-bit executable x86_64
/Applications/Xcode.app/Contents/Developer/usr/bin/make (for architecture arm64):	Mach-O 64-bit executable arm64

$ file $(which make)
command not found: whch
/usr/bin/make: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e]
/usr/bin/make (for architecture x86_64):	Mach-O 64-bit executable x86_64
/usr/bin/make (for architecture arm64e):	Mach-O 64-bit executable arm64e
/Applications/Xcode.app/Contents/Developer/usr/bin/make = arm64
$(which make) = arm64e
$ file /usr/lib/dyld

/usr/lib/dyld: Mach-O universal binary with 3 architectures: [i386:Mach-O dynamic linker i386] [x86_64:Mach-O 64-bit dynamic linker x86_64] [arm64e]
/usr/lib/dyld (for architecture i386):	Mach-O dynamic linker i386
/usr/lib/dyld (for architecture x86_64):	Mach-O 64-bit dynamic linker x86_64
/usr/lib/dyld (for architecture arm64e):	Mach-O 64-bit dynamic linker arm64e

I tried using the arm64 make version and it didn't fix the issue.

vjpr avatar Feb 04 '22 03:02 vjpr

@hsbt How can I view the Makefile in the build dir after error. The dir seems to be cleaned up on failure making it hard to debug.

current directory: /Users/Vaughan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/rbs-2.0.0/ext/rbs_extension
make DESTDIR\\= clean

Something in that makefile is causing the dyld error.

vjpr avatar Feb 04 '22 03:02 vjpr

@vjpr you can tell ruby-build to keep the sources i think, i did:

➜ export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected])"
➜ ~/.rbenv/plugins/ruby-build/bin/ruby-build -kv 3.1.0 /tmp/ruby-3.1.0

solaris007 avatar Feb 04 '22 04:02 solaris007

I'm having a similar issue trying to upgrade Ruby to 3.1.0 using Homebrew on Linux.

In my case, it seems that rbs-2.0.0 is trying to use system libraries (/lib64/libc.so.6) rather than the upgraded Homebrew one ($HOME/.linuxbrew/lib/libc.so.6) at compile time.

This results in the following error in .cache/Homebrew/Logs/ruby:

current directory: /home/etiennes/.linuxbrew/Cellar/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rbs-2.0.0/ext/rbs_extension
/usr/bin/make DESTDIR\\= clean
/usr/bin/make: relocation error: /home/etiennes/.linuxbrew/lib/libpthread.so.0: symbol __libc_vfork, version GLIBC_PRIVATE not defined in file libc.so.6 with link time reference

current directory: /home/etiennes/.linuxbrew/Cellar/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rbs-2.0.0/ext/rbs_extension
/usr/bin/make DESTDIR\\=
/usr/bin/make: relocation error: /home/etiennes/.linuxbrew/lib/libpthread.so.0: symbol __libc_vfork, version GLIBC_PRIVATE not defined in file libc.so.6 with link time reference

make failed, exit code 127

When looking at the different versions of libc.so.6 on my machine:

$ readelf -s $HOME/.linuxbrew/lib/libc.so.6 | grep "__libc_vfork"
  5324: 00000000000b9890    75 FUNC    GLOBAL DEFAULT   15 __libc_vfork
$ readelf -s /lib64/libc.so.6 | grep "__libc_vfork"
$

Homebrew has no problem installing v3.0.3 ([email protected]) alongside rbs-1.4.0

etiennepellegrini avatar Feb 09 '22 19:02 etiennepellegrini

I could install Ruby 3.1.0 with M1 macOS.

Me too but not 3.1.2. Getting "incompatible architecture (have 'arm64', need 'arm64e')". Tried with both rbenv and asdf.

james-em avatar May 10 '22 17:05 james-em

I cannot install Ruby 3.1.x too (on M1 Pro macOS Monterey) with the same need 'arm64e" error, wonder if I can choose specific rbs version to install Ruby?

narze avatar Jun 18 '22 08:06 narze

Any update on this? Same problem.. highly frustrating. We need to revert back to older version for now? What would be the latest version that should work on Apple silicon?

Jarrodsz avatar Jun 28 '22 10:06 Jarrodsz

Any update on this? Same problem.. highly frustrating. We need to revert back to older version for now? What would be the latest version that should work on Apple silicon?

Weird thing is that on a clean installed Monterey I was able to install 3.1.1. Prior formatting I wasn't

james-em avatar Jun 28 '22 10:06 james-em

Im having the same issue, is there a resolution?

jin-ahn avatar Aug 18 '22 22:08 jin-ahn

Hi, ruby-build maintainer's here.

I could install Ruby 3.1.0 with M1 macOS.

@hsbt the issue still stands for an installation with rbenv (I have the same issue as mentionned by op, and I believe the same issue as the above 3 comments). Where you able to install with ruby-build? And with ruby-build using rbenv?

In the mean time, the solution I found is a mix of above comments:


tmpdir=$(mktemp -d)
cd $tmpdir
version=3.1.2 # Set another 3.1.X version if you want here.
curl -O https://cache.ruby-lang.org/pub/ruby/3.1/ruby-$version.tar.gz
tar xvf ruby-$version.tar.gz
cd ruby-$version
./configure \
	--with-openssl-dir="$(brew --prefix [email protected])" \
	--prefix="$(rbenv root)/versions/$version" # Install where rbenv would have installed it
make && make install
rm -rf $tmpdir

BuonOmo avatar Aug 30 '22 09:08 BuonOmo

Where you able to install with ruby-build? And with ruby-build using rbenv?

Yes. I could install it today.

$ rbenv install 3.1.2
To follow progress, use 'tail -f /var/folders/_z/1_hsk6zx07v57yg5wlsjxvc80000gn/T/ruby-build.20220830184246.51183.log' or pass --verbose
Installing openssl-3.0.5...
Installed openssl-3.0.5 to /Users/hsbt/.local/share/rbenv/versions/3.1.2

Downloading ruby-3.1.2.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.2.tar.gz
Installing ruby-3.1.2...
ruby-build: using readline from homebrew
Installed ruby-3.1.2 to /Users/hsbt/.local/share/rbenv/versions/3.1.2

hsbt avatar Aug 30 '22 09:08 hsbt

I guess there is something already install of our computers that make it fail then (as suggested in this ruby-build discussion).

BuonOmo avatar Aug 30 '22 10:08 BuonOmo

Yes, I'm not sure why it's failed.

And We should move to https://github.com/rbenv/ruby-build/discussions/1961

hsbt avatar Aug 30 '22 10:08 hsbt

Hmm, I have no idea to do for this issue. It would be a problem of ruby-build or rbenv, or maybe homebrew?

To clarify this is an issue of CRuby + darwin-arm64, it's independent of ruby-build besides the fact that ruby-build defaults to --enable-shared: https://bugs.ruby-lang.org/issues/19920

eregon avatar Oct 12 '23 11:10 eregon