Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please use $HOMEBREW_PREFIX and/or brew --prefix to add a library path #1030

Open
xeron opened this issue May 2, 2023 · 3 comments
Open

Comments

@xeron
Copy link

xeron commented May 2, 2023

Hi!

I'm struggling with making ruby-vips/ffi work with custom Homebrew location on Intel mac:

$ brew --prefix
/opt/brew
$ echo $HOMEBREW_PREFIX
/opt/brew

It fails with:

$ bundle exec rails c
Loading development environment (Rails 7.0.4.3)
3.2.2 :001 > require 'vips'
…/bundle/ruby/3.2.0/gems/ffi-1.15.5/lib/ffi/library.rb:145:in `block in ffi_lib': Could not open library 'glib-2.0.0': dlopen(glib-2.0.0, 0x0005): tried: 'glib-2.0.0' (no such file), '/System/Volumes/Preboot/Cryptexes/OSglib-2.0.0' (no such file), '/usr/lib/glib-2.0.0' (no such file, not in dyld cache), 'glib-2.0.0' (no such file), '/usr/local/lib/glib-2.0.0' (no such file), '/usr/lib/glib-2.0.0' (no such file, not in dyld cache). (LoadError)
Could not open library 'libglib-2.0.0.dylib': dlopen(libglib-2.0.0.dylib, 0x0005): tried: 'libglib-2.0.0.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibglib-2.0.0.dylib' (no such file), '/usr/lib/libglib-2.0.0.dylib' (no such file, not in dyld cache), 'libglib-2.0.0.dylib' (no such file), '/usr/local/lib/libglib-2.0.0.dylib' (no such file), '/usr/lib/libglib-2.0.0.dylib' (no such file, not in dyld cache)

Setting the following doesn't help:

$ export LD_LIBRARY_PATH=/opt/brew/lib
$ export DYLD_LIBRARY_PATH=/opt/brew/lib
$ export DYLD_FALLBACK_LIBRARY_PATH=/opt/brew/lib

In fact I think ruby sets DYLD_LIBRARY_PATH and DYLD_FALLBACK_LIBRARY_PATH to nil on load:

$ export DYLD_FALLBACK_LIBRARY_PATH=/opt/brew/lib
$ echo $DYLD_FALLBACK_LIBRARY_PATH
/opt/brew/lib
$ export DYLD_LIBRARY_PATH=/opt/brew/lib
$ echo $DYLD_LIBRARY_PATH
/opt/brew/lib
$ irb
3.2.2 :001 > ENV['DYLD_FALLBACK_LIBRARY_PATH']
 => nil
3.2.2 :002 > ENV['DYLD_LIBRARY_PATH']
 => nil

I saw a discussion in #968 about using ENV['HOMEBREW_PREFIX'] or brew --prefix shellout to get an extra library path and I think this would solve my issue.

Using ffi from the master branch didn't fix the issue. I've added the following code to dynamic_library.rb as an experiment:

    unless ENV['HOMEBREW_PREFIX'].to_s.empty?
      SEARCH_PATH << File.join(ENV['HOMEBREW_PREFIX'], 'lib')
    end

and it finally worked.

@skull-squadron
Copy link

DYLD_FALLBACK_LIBRARY_PATH and DYLD_LIBRARY_PATH are not unset. spring would cause this behavior because it doesn't inherit the current environment.

Not every system has or needs Homebrew, so this should never be a requirement.

Instead of bleeding at and guessing at dependencies, gem authors should be able to adjust dylib search path(s). Without this ability, or by guessing incorrectly, things break at scale such as isolated, vendored environments.

image

@xeron
Copy link
Author

xeron commented May 16, 2023

DYLD_FALLBACK_LIBRARY_PATH and DYLD_LIBRARY_PATH are not unset. spring would cause this behavior because it doesn't inherit the current environment.

My irb shell inherits LD_LIBRARY_PATH tho. But not DYLD_FALLBACK_LIBRARY_PATH / DYLD_LIBRARY_PATH.

Not every system has or needs Homebrew, so this should never be a requirement.

Instead of bleeding at and guessing at dependencies, gem authors should be able to adjust dylib search path(s). Without this ability, or by guessing incorrectly, things break at scale such as isolated, vendored environments.

ffi already guesses homebrew libs location, my suggestion is to use more reliable mechanisms for that:

https://github.com/ffi/ffi/blob/73c36d77d76ef681cade4c4024abfe73af8a38b6/lib/ffi/dynamic_library.rb#L33C1-L36

@skull-squadron
Copy link

skull-squadron commented May 16, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants