Skip to content

Instantly share code, notes, and snippets.

@bennyfactor
Last active February 23, 2023 05:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennyfactor/34fa8619a02e01e36e68540c069f8590 to your computer and use it in GitHub Desktop.
Save bennyfactor/34fa8619a02e01e36e68540c069f8590 to your computer and use it in GitHub Desktop.
How to rebuild old ruby on modern macos, because of course the headers moved and bundler suddenly can't build native extensions any more
# This is based on https://gist.github.com/whitehat101/87c06c29dabfe15f094ec331b77a7c6d and https://solitum.net/openssl-os-x-el-capitan-and-brew/
# I take no responsibility for the damage it may do to any other build system you run.
# Disable system integrity protection before this mess.
# Uninstall everything critical to get back to baseline
rbenv uninstall ree-1.8.7-2012.02
# also make sure any old versions of openssl and gcc you have installed thru brew are uninstalled
# make sure you have all this crap installed, even though the build may not touch some of these
brew install openssl libyaml libffi readline libxml2
# reinstall gcc
brew install gcc@6
# upgrade ruby-build, which you probably have already and may be the problem, this is a rats' nest
brew upgrade ruby-build
# install old openssl 0.9.8 because who cares about safety or anything, this is a development environment and we need old headers
# brew install https://github.com/Homebrew/homebrew-versions/raw/586b7e9012a3ed1f9df6c43d0483c65549349289/openssl098.rb
# Homebrew is now very grouchy about installing random formulae from github urls, so here's some additional rigamarole:
brew tap-new oldssl/openssl098
curl -L https://raw.githubusercontent.com/Homebrew/homebrew-cask-versions/586b7e9012a3ed1f9df6c43d0483c65549349289/openssl098.rb -o /usr/local/Homebrew/Library/Taps/oldssl/homebrew-openssl098/Formula/openssl098.rb
sed -i '' 's/MacOS\.prefer_64_bit\?/Hardware\:\:CPU\.is_64_bit\?/g' /usr/local/Homebrew/Library/Taps/oldssl/homebrew-openssl098/Formula/openssl098.rb
sed -i '' 's/by_osx/by_macos/g' /usr/local/Homebrew/Library/Taps/oldssl/homebrew-openssl098/Formula/openssl098.rb
brew style --fix /usr/local/Homebrew/Library/Taps/oldssl/homebrew-openssl098/Formula/openssl098.rb
brew install --build-from-source openssl098
# # Un-comment out the below two commands if this script doesn't work the first time.
# # You're gonna take yourself right into the danger zone with this one. Symlink the old openssl headers into your lib.
# # Rbenv install doesn't always honor ldflags for some reason (we will use them anyway later)
# cd /usr/local/include
# ln -s ../opt/openssl098/include/openssl .
# install ree-187
CC=gcc-6 \
CFLAGS="-O2 -fno-tree-dce -fno-optimize-sibling-calls -I/usr/local/Cellar/openssl098/0.9.8zh/include -I/usr/local/opt/libxml2/include" \
CPPFLAGS="-I/usr/local/opt/libxml2/include" \
LDFLAGS="-L/usr/local/Cellar/openssl098/0.9.8zh/lib -L/usr/local/opt/libxml2/lib" \
rbenv install ree-1.8.7-2012.02
# make sure we're in the right ruby to test/install stuff
rbenv shell ree-1.8.7-2012.02
# the following should output "OK"; if it doesn't, you need to go into the danger zone (above)
ruby -ropenssl -e "puts :OK"
# install core gems that are old enough to work with this version of ruby
gem install rdoc -v 4.2.0
gem install rdoc-data
rbenv rehash
rdoc-data --install
gem install builder -v 3.2.3
gem install bundler -v 1.16.2
bundle config build.nokogiri --use-system-libraries --with-xml2-include=$(brew --prefix libxml2)/include/libxml2
bundle config build.mysql --with-opt-lib=/usr/local/Cellar/openssl098/0.9.8zh/lib
# This worked for me. Builds native extensions again and everything. Will it work for you? Let's hope so. If not? Too bad.
# This is based on https://gist.github.com/whitehat101/87c06c29dabfe15f094ec331b77a7c6d and https://solitum.net/openssl-os-x-el-capitan-and-brew/
# I take no responsibility for the damage it may do to any other build system you run.
# Uninstall everything critical to get back to baseline
brew remove apple-gcc42
rbenv uninstall ree-1.8.7-2012.02
# also make sure any old versions of openssl you have installed thru brew are uninstalled
# make sure you have all this crap installed, even though the build may not touch some of these
brew install openssl libyaml libffi readline
# reinstall gcc-42
brew tap homebrew/dupes && brew install apple-gcc42
# upgrade ruby-build, which you probably have already and may be the problem, this is a rats' nest
brew upgrade ruby-build
# install old openssl 0.9.8 because who cares about safety or anything, this is a development environment and we need old headers
brew install https://github.com/Homebrew/homebrew-versions/raw/586b7e9012a3ed1f9df6c43d0483c65549349289/openssl098.rb
# take yourself right into the danger zone with this one. Symlink the old openssl headers into your lib.
# Rbenv install doesn't always honor ldflags for some reason (we will use them anyway later)
cd /usr/local/include
ln -s ../opt/openssl098/include/openssl .
# install ree-187
LDFLAGS="-L/usr/local/opt/openssl098/lib" CPPFLAGS="-I/usr/local/opt/openssl098/include" PKG_CONFIG_PATH="/usr/local/opt/openssl098/lib/pkgconfig" RUBY_CONFIGURE_OPTS=--with-readline-dir="$(brew --prefix readline)" rbenv install 1.8.7-p352
# install a version of bundler that works with antique Gemfiles, but modern enough for rack-reverse-proxy-0.11.0 [bundler (~> 1.7)]
gem install bundler -v 1.7.15
# This worked for me. Builds native extensions again and everything. Will it work for you? Let's hope so. If not? Too bad.
@bennyfactor
Copy link
Author

bennyfactor commented May 7, 2020

Here's an addendum. I haven't rebuilt anything in catalina yet, since the sierra build seems to work still.

But, you're gonna need new openssl root certs to connect to rubygems et al.

cd /usr/local/etc/openssl
curl -OL http://curl.haxx.se/ca/cacert.pem
mv cacert.pem cert.pem

@schmijos
Copy link

Installing from a local formula does not require manifests (which don't exist) to be downloaded:

brew install --build-from-source /usr/local/Homebrew/Library/Taps/oldssl/homebrew-openssl098/openssl098.rb

@bennyfactor
Copy link
Author

@schmijos are you running that command in lieu of line 29 of the Catalina script above? That full path causes brew to return Error: No available formula or cask with the name "/usr/local/Homebrew/Library/Taps/oldssl/homebrew-openssl098/openssl098.rb". for me. However, you are right that the build from source flag will keep brew from needlessly hitting bintray for something that no longer exists.

I have updated the script to take that into account. Thanks so much!

@schmijos
Copy link

Oh, yes. I guess I forgot Formula in the file path 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment