Project

General

Profile

Actions

Bug #18758

closed

Ruby fails to build on M1 Mac when x86 Homebrew is installed

Added by tenderlovemaking (Aaron Patterson) almost 2 years ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:108424]

Description

If you install x86 homebrew on an M1 mac, then install libyaml in the x86 version of homebrew, Ruby will fail to build on ARM.

Steps to reproduce:

  1. Install x86 homebrew: $ arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  2. Install x86 libyaml: $ arch -x86_64 /usr/local/bin/brew install libyaml
  3. Configure and compile Ruby with ARM architecture

I expected Ruby to compile, but Psych fails with the following output:

/Users/aaron/git/ruby/tool/extlibs.rb:6:in `require': cannot load such file -- digest (LoadError)
	from /Users/aaron/git/ruby/tool/extlibs.rb:6:in `<top (required)>'
	from /Users/aaron/git/ruby/ext/psych/extconf.rb:24:in `require_relative'
	from /Users/aaron/git/ruby/ext/psych/extconf.rb:24:in `<top (required)>'
	from ./ext/extmk.rb:217:in `load'
	from ./ext/extmk.rb:217:in `block in extmake'
	from /Users/aaron/git/ruby/lib/mkmf.rb:324:in `open'
	from ./ext/extmk.rb:213:in `extmake'
	from ./ext/extmk.rb:577:in `block in <main>'
	from ./ext/extmk.rb:573:in `each'
	from ./ext/extmk.rb:573:in `<main>'

mkmf.log from Psych says:

ld: warning: ignoring file /usr/local/lib/libyaml.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64

I believe the problem is the default LDFLAGS set by configure. The output of configure is:

   * LDFLAGS:             -L. -fstack-protector-strong -L/usr/local/lib

I don't think /usr/local/lib should be in LDFLAGS by default.

I've attached a patch that fixes the problem for me, and I sent the same patch as a PR on GitHub: https://github.com/ruby/ruby/pull/5855

Thanks!


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #18790: cannot load such file -- digest (LoadError)Closedhsbt (Hiroshi SHIBATA)Actions

Updated by tenderlovemaking (Aaron Patterson) almost 2 years ago

I tried to attach the patch but it just says "internal server error" 😅

redmin screenshot

Updated by mame (Yusuke Endoh) almost 2 years ago

I don't think /usr/local/lib should be in LDFLAGS by default.

When removing what appears to be unnecessary, it is a good idea to check the reason why it was introduced. According to https://github.com/ruby/ruby/commit/67da4aebc56b1a1058ab17e256f7d64b6b8bbd90, -L/usr/local/lib was needed to support the weird behavior of apple gcc port in 2009. Maybe the issue has been fixed in the macOS side, so I agree with the change.

Updated by tenderlovemaking (Aaron Patterson) almost 2 years ago

mame (Yusuke Endoh) wrote in #note-2:

I don't think /usr/local/lib should be in LDFLAGS by default.

When removing what appears to be unnecessary, it is a good idea to check the reason why it was introduced. According to https://github.com/ruby/ruby/commit/67da4aebc56b1a1058ab17e256f7d64b6b8bbd90, -L/usr/local/lib was needed to support the weird behavior of apple gcc port in 2009. Maybe the issue has been fixed in the macOS side, so I agree with the change.

Yes, I checked that. I think the weird behavior is fixed, but the commit message didn't describe the weird behavior so I don't know how to test if it's fixed.

Actions #5

Updated by jeremyevans0 (Jeremy Evans) almost 2 years ago

  • Is duplicate of Bug #18790: cannot load such file -- digest (LoadError) added
Actions #6

Updated by hsbt (Hiroshi SHIBATA) over 1 year ago

  • Status changed from Open to Closed

The download feature for libyaml and libffi with extlibs has been removed from Ruby 3.2.0-preview2.

This issue no longer happened.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0