ruby-build
ruby-build copied to clipboard
Add support for pkg-config
When pkg-config is installed and finds the libraries, use those rather than relying on Homebrew or bundling OpenSSL.
Fixes https://github.com/rbenv/ruby-build/issues/2544
A few comments about package managers
- I've tried hard not to break things for Homebrew. When the libraries and pkg-config have been installed using Homebrew, pkg-config finds the libraries in
/opt/homebrew/Cellar/. However, those have their version number in the path, so I decided to ignore any library in*/Cellar/*to avoid breaking Ruby when runningbrew upgrade. - When the libraries and pkg-config have been installed using different package managers, whoever comes first in the search path wins.
- A package manager that distributes ruby-build should have pkg-config as a dependency as well as all required and optional libraries (openssl, readline, libffi, gmp) to make sure all the linked libraries come from the same source.
Alternatives considered
Skip --with-xyz-dir=
pkg-config is used internally by Ruby build scripts. So my initial idea was to skip the --with-xyz-dir= option when a library is discovered by pkg-config and let the build scripts do their job. However:
- That doesn't work for gmp.
- That may not work for other libraries with older Rubies.
- Having the
--with-xyz-dir=options appear in the output is helpful to make sure that the correct libraries are used. - "Explicit is better than implicit." 😉
Do nothing
My goal was to write a simple fix to have ruby-build work well with MacPorts (and other package managers). But doing so without breaking things turned out a little more complex than anticipated. Maybe it's just not worth it.