Skip to content

Instantly share code, notes, and snippets.

@rdetert
Last active February 11, 2021 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdetert/a657299c17fa3c06cf33f36d7efeada2 to your computer and use it in GitHub Desktop.
Save rdetert/a657299c17fa3c06cf33f36d7efeada2 to your computer and use it in GitHub Desktop.
Get Ruby stuff to compile on Apple Silicon M1
Here are my notes on getting the codebase to work on the new M1 processors:
Upgrade the Ruby version to 2.7.2. You may need to set some compiler flags such as:
RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install 2.7.2
Update all gems with 'bundle update'
Modify the Gemfile to detect the new hardware:
if RUBY_PLATFORM =~ /arm64.*darwin/ && `sysctl -n machdep.cpu.brand_string` =~ /M1/
# Get things to compile for Apple Silicon - minimum Ruby version of 2.7.2
# gem 'mini_racer', :platforms => :ruby, git: 'https://github.com/rubyjs/mini_racer.git'
gem 'mini_racer', github: 'rubyjs/mini_racer', branch: 'refs/pull/186/head'
gem 'ffi', '~> 1.14.2'
gem 'pg' # postgres
else
gem 'therubyracer', :platforms => :ruby
#gem 'libv8', '~> 3.21'
gem 'pg', '~> 0.2' # postgres
end
Gem FFI is a dependency that must be upgraded to the latest or possibly compiled with extra compiler flags like so:
gem install ffi -v '1.9.21' -- --with-cflags="-Wno-error=implicit-function-declaration"
TheRubyRacer is no longer in active development and needs to be replaced with another like MiniRacer and pulled from the main branch on Github.
https://github.com/rubyjs/mini_racer/issues/185
Another dependent gem TCLink must be linked manually to newer version of OpenSSL
gem install tclink_gs -v '4.5.0' -- --with-opt-include=$(brew --prefix openssl)/include
As always, the PG gem will likely need to be told where pg_config is. I use Postgres.app but their latest build doesn't include M1 headers. I opened a Github issue with them and they are trying to put out a new build. Meanwhile I had to use Homebrew. The command looks something like:
gem install pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
https://github.com/ffi/ffi/issues/869#issuecomment-752123090
https://github.com/ffi/ffi/issues/611
https://github.com/ffi/ffi/issues/611#issuecomment-694201967
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment