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

Automatically detect and link to Homebrew's libyaml #1929

Merged
merged 3 commits into from
Mar 6, 2023

Conversation

dreyks
Copy link
Contributor

@dreyks dreyks commented Feb 3, 2022

closes #1928

turns out there already was a test for this behaviour but it was falsely passing due to needs_yaml (that was run only from tests) was calling use_homebrew_yaml (which was otherwise not called in production)

Bash is not my native language and I've had very limited experience with BATS framework so there might be things I've done wrong :)

bin/ruby-build Outdated Show resolved Hide resolved
test/build.bats Outdated Show resolved Hide resolved
@dreyks dreyks mentioned this pull request Feb 3, 2022
Copy link
Member

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on! Left some style suggestions

bin/ruby-build Outdated
local libdir="$(brew --prefix libyaml 2>/dev/null || true)"
if [ -d "$libdir" ]; then
local libdir="$(homebrew_yaml_dir)"
if [ ! -z "$libdir" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use -n instead of ! -z

bin/ruby-build Outdated
@@ -1022,20 +1023,28 @@ locate_llvm() {
}

needs_yaml() {
[[ "$RUBY_CONFIGURE_OPTS" != *--with-libyaml-dir=* ]] &&
! use_homebrew_yaml
[ -z "$(homebrew_yaml_dir)" ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For backwards compatibility, please restore to the old implementation of needs_yaml. There was no need to change it, and the new implementation doesn't print the line ruby-build: using libyaml from homebrew anymore.

bin/ruby-build Outdated
homebrew_yaml_dir() {
if [[ "$RUBY_CONFIGURE_OPTS" != *--with-libyaml-dir=* ]]; then
local libdir="$(brew --prefix libyaml 2>/dev/null || true)"
if [[ -d "$libdir" ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: double brackets are not needed here, please use single ones

bin/ruby-build Outdated
echo "ruby-build: using libyaml from homebrew"
package_option ruby configure --with-libyaml-dir="$libdir"
else
return 1
fi
}

homebrew_yaml_dir() {
if [[ "$RUBY_CONFIGURE_OPTS" != *--with-libyaml-dir=* ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be surprising that a function called homebrew_yaml_dir performs this check first. I would rather that the caller of homebrew_yaml_dir performs the check instead, even if that's going to lead to some repetition. Explicitness is better than burying some magic behavior deep down a call chain

@dreyks
Copy link
Contributor Author

dreyks commented Feb 8, 2022

thanks for the review, @mislav!

I ended up reverting most of my changes and instead dropped the fixture usage in favor of an inline definition to avoid future false negatives in this test

@dreyks dreyks requested a review from mislav February 8, 2022 09:20
@dreyks
Copy link
Contributor Author

dreyks commented Mar 8, 2022

anything else I need to do to move this forward?

@mislav
Copy link
Member

mislav commented Mar 8, 2022

Sorry for my inactivity. I was about to push some changes to PR a few weeks ago, but I got blocked on the inflexible stubbing support that we right now have in tests. So I'm going to try to improve that too. Nothing that you need to do for this PR anymore; thank you!

@KevDog
Copy link

KevDog commented Sep 10, 2022

I think I have issues this PR could fix. Trying to install on Ventura is bailing on not finding libyaml.

@mislav
Copy link
Member

mislav commented Sep 13, 2022

@KevDog In the meantime, you can explicitly set RUBY_CONFIGURE_OPTS=--with-libyaml-dir=/path/to/libyaml to work around this in your setup.

@bai
Copy link

bai commented Mar 1, 2023

Friendly bump 🙏🏼 Another use case is that package managers that depend on ruby-build, e.g. asdf are failing to install ruby and need more magic trickery to get this fixed.

carhartl added a commit to carhartl/dotfiles that referenced this pull request Mar 2, 2023
@eregon
Copy link
Member

eregon commented Mar 3, 2023

On a related note: https://twitter.com/eregontp/status/1631281524866678788

I guess this is only an issue on darwin-aarch64 and not darwin-amd64 because on the latter /usr/local/lib is part of the default library path. Maybe Homebrew should consider using /usr/local/lib or another place part of the default library path again on darwin-aarch64 and deal with "Rosetta vs not" in another way. That would be an issue for Homebrew of course.

But yeah for now I think we very much need this in ruby-build to workaround this broken OS called macOS which forces everything to hardcode paths for "system-like" packages. cc @mislav

dreyks and others added 2 commits March 6, 2023 19:14
Copy link
Member

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally fixed the tests. Thanks for the patience!

@mislav mislav changed the title support libyaml from homebrew Automatically detect and link to Homebrew's libyaml Mar 6, 2023
@mislav mislav merged commit 784d7b7 into rbenv:master Mar 6, 2023
halostatue added a commit to halostatue/macports-ports that referenced this pull request Mar 9, 2023
20230306:

- Add mruby-3.2.0 by @hasumikin in rbenv/ruby-build#2155
- Automatically detect and link to Homebrew's libyaml by @dreyks in rbenv/ruby-build#1929

20230309:

- Add JRuby 9.4.2.0 by @headius in rbenv/ruby-build#2160
herbygillot pushed a commit to macports/macports-ports that referenced this pull request Mar 9, 2023
20230306:

- Add mruby-3.2.0 by @hasumikin in rbenv/ruby-build#2155
- Automatically detect and link to Homebrew's libyaml by @dreyks in rbenv/ruby-build#1929

20230309:

- Add JRuby 9.4.2.0 by @headius in rbenv/ruby-build#2160
@KevDog
Copy link

KevDog commented Mar 10, 2023

Thanks!

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

Successfully merging this pull request may close these issues.

Use yaml from homebrew
5 participants