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

Can't install mysql2 gem after installing mysql 8.0.33 formula #131407

Closed
4 tasks done
dgholz opened this issue May 19, 2023 · 11 comments
Closed
4 tasks done

Can't install mysql2 gem after installing mysql 8.0.33 formula #131407

dgholz opened this issue May 19, 2023 · 11 comments
Labels
outdated PR was locked due to age stale No recent activity upstream issue An upstream issue report is needed

Comments

@dgholz
Copy link

dgholz commented May 19, 2023

brew gist-logs <formula> link OR brew config AND brew doctor output

brew config

HOMEBREW_VERSION: 4.0.18-100-ge850162
ORIGIN: https://github.com/Homebrew/brew
HEAD: e85016230efabcba8a9d12960ebd4fbc61369783
Last commit: 2 hours ago
Core tap origin: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 3743b8fe621df445ccb62f962b66fbb5e0a5e6cc
Core tap last commit: 4 days ago
Core tap branch: master
Core tap JSON: 19 May 15:26 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: /private/tmp/com.apple.launchd.sUu1EpySPo/org.macosforge.xquartz:0
HOMEBREW_MAKE_JOBS: 10
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: 10-core 64-bit arm_firestorm_icestorm
Clang: 14.0.3 build 1403
Git: 2.40.1 => /opt/homebrew/bin/git
Curl: 7.87.0 => /usr/bin/curl
macOS: 13.3.1-arm64
CLT: 14.3.0.0.1.1679647830
Xcode: N/A
Rosetta 2: false

brew doctor

Your system is ready to brew.

Verification

  • My "brew doctor output" says Your system is ready to brew. and am still able to reproduce my issue.
  • I ran brew update and am still able to reproduce my issue.
  • I have resolved all warnings from brew doctor and that did not fix my problem.
  • I searched for recent similar issues at https://github.com/Homebrew/homebrew-core/issues?q=is%3Aissue and found no duplicates.

What were you trying to do (and why)?

bundle install in a repo with a Gemfile like

source "https://rubygems.org"
gem "mysql2"

What happened (include all command output)?

Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using bundler 2.4.12
Installing mysql2 0.5.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/danielholz/.gem/ruby/3.1.4/gems/mysql2-0.5.5/ext/mysql2
/Users/danielholz/.rubies/ruby-3.1.4/bin/ruby extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_gc_mark_movable()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enc_interned_str() in ruby.h... yes
/opt/homebrew/bin/brew
-----
Using mysql_config at /opt/homebrew/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes
checking for MYSQL.net.vio in mysql.h... yes
checking for MYSQL.net.pvio in mysql.h... no
checking for MYSQL_DEFAULT_AUTH in mysql.h... yes
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes
checking for my_bool in mysql.h... no
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /opt/homebrew/Cellar/mysql/8.0.33/lib
-----
creating Makefile

current directory: /Users/danielholz/.gem/ruby/3.1.4/gems/mysql2-0.5.5/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20230519-54884-t4q2sk sitelibdir\=./.gem.20230519-54884-t4q2sk clean

current directory: /Users/danielholz/.gem/ruby/3.1.4/gems/mysql2-0.5.5/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20230519-54884-t4q2sk sitelibdir\=./.gem.20230519-54884-t4q2sk
compiling client.c
In file included from client.c:15:
./mysql_enc_name_to_ruby.h:43:1: warning: a function declaration without a prototype is deprecated in all versions of C and is not
supported in C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb_hash (str, len)
^
./mysql_enc_name_to_ruby.h:86:1: warning: a function declaration without a prototype is deprecated in all versions of C and is not
supported in C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb (str, len)
^
2 warnings generated.
compiling infile.c
compiling mysql2_ext.c
compiling result.c
result.c:304:35: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
        precision = field->length - (field->decimals > 0 ? 2 : 1);
                  ~ ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lzstd
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/danielholz/.gem/ruby/3.1.4/gems/mysql2-0.5.5 for inspection.
Results logged to /Users/danielholz/.gem/ruby/3.1.4/extensions/arm64-darwin-22/3.1.0-static/mysql2-0.5.5/gem_make.out

  /Users/danielholz/.rubies/ruby-3.1.4/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:119:in `run'
  /Users/danielholz/.rubies/ruby-3.1.4/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:51:in `block in make'
  /Users/danielholz/.rubies/ruby-3.1.4/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:43:in `each'
  /Users/danielholz/.rubies/ruby-3.1.4/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:43:in `make'
  /Users/danielholz/.rubies/ruby-3.1.4/lib/ruby/site_ruby/3.1.0/rubygems/ext/ext_conf_builder.rb:41:in `build'
  /Users/danielholz/.rubies/ruby-3.1.4/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:187:in `build_extension'
  /Users/danielholz/.rubies/ruby-3.1.4/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:221:in `block in build_extensions'
  /Users/danielholz/.rubies/ruby-3.1.4/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:218:in `each'
  /Users/danielholz/.rubies/ruby-3.1.4/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:218:in `build_extensions'
  /Users/danielholz/.rubies/ruby-3.1.4/lib/ruby/site_ruby/3.1.0/rubygems/installer.rb:843:in `build_extensions'
  /Users/danielholz/.gem/ruby/3.1.4/gems/bundler-2.4.12/lib/bundler/rubygems_gem_installer.rb:72:in `build_extensions'
  /Users/danielholz/.gem/ruby/3.1.4/gems/bundler-2.4.12/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /Users/danielholz/.gem/ruby/3.1.4/gems/bundler-2.4.12/lib/bundler/source/rubygems.rb:198:in `install'
  /Users/danielholz/.gem/ruby/3.1.4/gems/bundler-2.4.12/lib/bundler/installer/gem_installer.rb:54:in `install'
  /Users/danielholz/.gem/ruby/3.1.4/gems/bundler-2.4.12/lib/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  /Users/danielholz/.gem/ruby/3.1.4/gems/bundler-2.4.12/lib/bundler/installer/parallel_installer.rb:156:in `do_install'
  /Users/danielholz/.gem/ruby/3.1.4/gems/bundler-2.4.12/lib/bundler/installer/parallel_installer.rb:147:in `block in worker_pool'
  /Users/danielholz/.gem/ruby/3.1.4/gems/bundler-2.4.12/lib/bundler/worker.rb:62:in `apply_func'
  /Users/danielholz/.gem/ruby/3.1.4/gems/bundler-2.4.12/lib/bundler/worker.rb:57:in `block in process_queue'
  /Users/danielholz/.gem/ruby/3.1.4/gems/bundler-2.4.12/lib/bundler/worker.rb:54:in `loop'
  /Users/danielholz/.gem/ruby/3.1.4/gems/bundler-2.4.12/lib/bundler/worker.rb:54:in `process_queue'
  /Users/danielholz/.gem/ruby/3.1.4/gems/bundler-2.4.12/lib/bundler/worker.rb:90:in `block (2 levels) in create_threads'

An error occurred while installing mysql2 (0.5.5), and Bundler cannot continue.

In Gemfile:
  mysql2

What did you expect to happen?

That the mysql2 gem would compile its native extensions and install without error.

Step-by-step reproduction instructions (by running brew commands)

`brew install mysql`

and then `gem install mysql2`, or creating a Gemfile & running Bundler as described.

Just to be extra certain:
* remove any stored Bundler config: `bundle config unset build.mysql2`
* delete existing extension bundles and settings: `rm -rf "$(gem environment home)"/{build_info,extensions/*-darwin-*/*-static,specifications,gems}/mysql2-0.5.5*`
@dgholz dgholz added the bug Reproducible Homebrew/homebrew-core bug label May 19, 2023
@SMillerDev
Copy link
Member

Did you report this to the authors of the gem? Because I'm not sure how this could be a package issue on brews side.

@dgholz
Copy link
Author

dgholz commented May 19, 2023

Very similar to #130258: the output from /opt/homebrew/opt/mysql/bin/mysql_config directs the linker to use libzstd, but the path to the library isn't included in the output.

I guess it should have -L/opt/homebrew/opt/libzstd/lib or -L/opt/homebrew/lib.

@carlocab
Copy link
Member

Try doing

export LDFLAGS=-L/opt/homebrew/lib

@dgholz
Copy link
Author

dgholz commented May 19, 2023

export LDFLAGS=-L/opt/homebrew/lib

No change. I don't think Ruby's extconf system passes this through to the underlying Makefiles.

@dgholz
Copy link
Author

dgholz commented May 19, 2023

Did you report this to the authors of the gem? Because I'm not sure how this could be a package issue on brews side.

I have not, I traced the cause to the output of the HomeBrew-provided mysql_config.

@carlocab
Copy link
Member

Try this:

/usr/bin/sed -i .bak -E -e '/^libs="\-L/ s;"$; -L/opt/homebrew/lib";' "$(brew --prefix mysql)/bin/mysql_config"

You can do rm "$(brew --prefix mysql)/bin/mysql_config.bak" if it works.

@Bo98
Copy link
Member

Bo98 commented May 20, 2023

This is another upstream bug. It used to be handled by: https://github.com/mysql/mysql-server/blob/ea7087d885006918ad54458e7aad215b1650312c/scripts/CMakeLists.txt#L334-L337

but this code is no longer executed after the change to use ext::zstd.

@carlocab carlocab added upstream issue An upstream issue report is needed and removed bug Reproducible Homebrew/homebrew-core bug labels May 20, 2023
@dgholz
Copy link
Author

dgholz commented May 22, 2023

@carlocab thanks for the suggestions. I'm indirectly asking people to use this library via a gem dependency, and to roll this out I'd have to direct them to manually edit the mysql_config. Right now the instructions are brew install mysql.

I can certainly do the edit. I reported this because I thought HomeBrew would provide a mysql_config that outputs the appropriate linker flags. I appreciate this is (again) an upstream bug and will be working on a patch for them.

@Bo98 aha, that's the code that would previously be called before the recent Makefile change (adding interfaces for the library dependencies).

@carlocab
Copy link
Member

I'm happy to apply a workaround to mysql_config as soon as this is reported upstream so it can at least be fixed at some point.

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale No recent activity label Jun 12, 2023
@carlocab
Copy link
Member

Closing this as an upstream issue.

Here's a workaround that can be applied to the formula:

diff --git a/Formula/mysql.rb b/Formula/mysql.rb
index aaf91e11ece..2fd11200b87 100644
--- a/Formula/mysql.rb
+++ b/Formula/mysql.rb
@@ -106,8 +106,10 @@ class Mysql < Formula
     system "cmake", "--install", "build"
 
     # Fix bad linker flags in `mysql_config`.
-    # https://bugs.mysql.com/bug.php?id=111011
-    inreplace bin/"mysql_config", "-lzlib", "-lz"
+    inreplace bin/"mysql_config" do |s|
+      s.gsub!("-lzlib", "-lz") # https://bugs.mysql.com/bug.php?id=111011
+      s.gsub!(/^libs="-L\$pkglibdir/, "\\0 -L#{HOMEBREW_PREFIX}/lib") # bug reference here
+    end
 
     (prefix/"mysql-test").cd do
       system "./mysql-test-run.pl", "status", "--vardir=#{Dir.mktmpdir}"

Feel free to open a pull request that applies this patch once it's been reported upstream. Replace bug reference here with the link to the bug report, of course.

@carlocab carlocab closed this as not planned Won't fix, can't repro, duplicate, stale Jun 17, 2023
@github-actions github-actions bot added the outdated PR was locked due to age label Jul 17, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age stale No recent activity upstream issue An upstream issue report is needed
Projects
None yet
Development

No branches or pull requests

4 participants