After many attempts and much searching I have a working answer. First, you have to have the two brews installed on your M1 Mac- homebrew under arm and homebrew (ibrew) under emulated x86. See https://soffes.blog/homebrew-on-apple-silicon for this. Then, I was able to install [email protected] under emulation, as well as openssl. This is needed because mysql2 is compiling under emulation, it seems, and is referencing those libraries.
ibrew install [email protected]
ibrew install openssl
I then needed to add mysql and its libraries to my PATH.
export PATH="/opt/homebrew/bin:/usr/local/bin:/opt/homebrew/opt/mysql:/opt/homebrew/opt/mysql/lib:/usr/local/Cellar//[email protected]//5.7.34:/usr/local/Cellar//[email protected]//5.7.34/lib:/usr/local/Cellar//[email protected]//5.7.34/bin:$PATH"
You might need to tweak this based on version numbers - and when you have it working put it in your ~/.zshrc or other shell initializer file.
Then I was able to install the mysql2 gem with these flags:
gem install mysql2 -V -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include --with-opt-dir="$(ibrew --prefix openssl)"
I'm not a C coder so I don't totally get the details of how mysql2 is linking up to the mysql libraries. I would prefer to use the available mysql under ARM, expecting it must run faster, but not sure how to get it to link up.
8.0.25_1
to8.0.26
for the specific version ofmsyql
we have installed. But the rest worked great. ProTip: I would actually configure Bundler to use this globally so that in the event that you need to reinstall the gem, it will use this configuration automatically. I've modified your answer with this approach. – Superaltar