Repository navigation
Update Ruby gem with arm64 binaries (Apple M1 support) #8199
Copy link
Copy link
Closed
Labels
macpackaging & distributionplatform relatedAny issue releated to specific platform or OSAny issue releated to specific platform or OSruby
Description
The Ruby gem is shipped with compiled extensions (via https://github.com/rake-compiler/rake-compiler), but it is missing arm64 binaries.
This results in errors like the following when installing the gem and requiring:
$ gem install google-protobuf
$ ruby -e 'require "google/protobuf"'
Traceback (most recent call last):
2: from -e:1:in `<main>'
1: from <snip>/rubygems/core_ext/kernel_require.rb:92:in `require'
<snip>/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- google/protobuf (LoadError)
6: from -e:1:in `<main>'
5: from <snip>/rubygems/core_ext/kernel_require.rb:156:in `require'
4: from <snip>/rubygems/core_ext/kernel_require.rb:168:in `rescue in require'
3: from <snip>/rubygems/core_ext/kernel_require.rb:168:in `require'
2: from <snip>/gems/google-protobuf-3.14.0-universal-darwin/lib/google/protobuf.rb:49:in `<top (required)>'
1: from <snip>/rubygems/core_ext/kernel_require.rb:92:in `require'
<snip>/rubygems/core_ext/kernel_require.rb:92:in `require': dlopen(<snip>/gems/google-protobuf-3.14.0-universal-darwin/lib/google/2.7/protobuf_c.bundle, 9): no suitable image found. Did find: (LoadError)
<snip>/gems/google-protobuf-3.14.0-universal-darwin/lib/google/2.7/protobuf_c.bundle: mach-o, but wrong architecture
<snip>/gems/google-protobuf-3.14.0-universal-darwin/lib/google/2.7/protobuf_c.bundle: mach-o, but wrong architecture - <snip>/gems/google-protobuf-3.14.0-universal-darwin/lib/google/2.7/protobuf_c.bundle
7: from -e:1:in `<main>'
6: from <snip>/rubygems/core_ext/kernel_require.rb:156:in `require'
5: from <snip>/rubygems/core_ext/kernel_require.rb:168:in `rescue in require'
4: from <snip>/rubygems/core_ext/kernel_require.rb:168:in `require'
3: from <snip>/gems/google-protobuf-3.14.0-universal-darwin/lib/google/protobuf.rb:48:in `<top (required)>'
2: from <snip>/gems/google-protobuf-3.14.0-universal-darwin/lib/google/protobuf.rb:51:in `rescue in <top (required)>'
1: from <snip>/rubygems/core_ext/kernel_require.rb:92:in `require'
<snip>/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- google/protobuf_c (LoadError)
A workaround is to force compilation of native extensions on install which works perfectly:
$ gem install google-protobuf --platform=ruby
or globally via this bundler setting:
$ bundle config set force_ruby_platform true
Related to #8062
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
macpackaging & distributionplatform relatedAny issue releated to specific platform or OSAny issue releated to specific platform or OSruby
Activity
LucaProvencal commentedon Feb 4, 2021
Confirmed that
$ bundle config set force_ruby_platform truein combination with grpc v1.35.0 upgrade solved this issue for me.
NielsKSchjoedt commentedon Mar 4, 2021
This still does not work for me. I have v. 3.15.3 installed and it throws this:
If I try to load the gem locally and alter lines inside
lib/google/protobuf.rblike so:I get:
Any clue why this happens?
NielsKSchjoedt commentedon Mar 4, 2021
Okay I tried updating to v
3.15.4then it worked. 1 hour later it suddenly stopped working again 🤯 Something is really fishy...I just tried to checkout the ruby gem and see if it could build, it cannot: #8372
teddy1004 commentedon May 17, 2021
solved on my new M1 Mac, try the following steps:
gem uninstall google-protobuf, and remove all google-protobufgem install google-protobuf -v 3.15.8 --platform=rubyor any version you wantseems bundle config force ruby platform not working, we have to reinstall google-protobuf platform: ruby from scratch
[-]Update Ruby gem with arm64 binaries (M1 support)[/-][+]Update Ruby gem with arm64 binaries (Apple M1 support)[/+]ericboehs commentedon Aug 30, 2021
None of these solutions worked for me on 3.17.3 on a 13" M1 MBP. I'm running the latest Monterey public beta (beta 5 I believe) so maybe that's the issue?
Installation went fine but when I go to require it I get a "No such file" error when looking for the arm64e bundle. Here's the full error:
I tried on Ruby 2.6.8p205 and 2.7.4p191. I tried recompiling Ruby several times using Xcode Command Line tools and the full version of Xcode (Mac App Store).
Overload119 commentedon Sep 8, 2021
Is there anyway to force bundler to use the Rubygems version installed with
--platform ruby?Whenever I run
bundleI see it's using theuniversal-darwinversion.I've tried doing
platform: :rubyto the line in the Gemfile but that doesn't work.bouk commentedon Oct 13, 2021
If you want to prevent bundler from installing these gems, add the following to you
Gemfile:This will overwrite bundler's platform matcher to ignore any universal gems
mloughran commentedon Oct 25, 2021
This was closed by #8232 (and released in 3.19.0).
ngan commentedon Oct 25, 2021
I'm not sure if this is actually fixed. I'm still getting the same problem (
protobuf_c.bundle: mach-o, but wrong architecture) after upgrading to3.19.0.I also don't see an

arm64-darwinbuild for3.19.0:acozzette commentedon Oct 28, 2021
I think some more work is required on the protobuf team's part before we can start publishing Mac arm64 binaries. The build is happening on an x86 machine and we probably need to tweak some things to get cross-compilation working.
jnarowski commentedon Dec 15, 2021
+1 for this
dangerrg commentedon Jan 7, 2022
I've tried all of the suggestions above, but still doesn't work for me:
I get this error:
I'm running on Mac M1:
nickmealey commentedon Jun 21, 2022
Updates on this issue? It appears to be ongoing and I'm only able to bundle with
bundle config set force_ruby_platform trueJasonLunn commentedon Sep 1, 2022
Similar to #8682, closing this because in version 3.22 protobuf is planning to experiment with releasing only a source gem.
If this experiment is unsuccessful and we revert to building binary gems for some platforms, we'll evaluate whether it makes sense to add arm64 darwin at that time.
CC: @deannagarcia @haberman
njmulsqb commentedon Jan 3, 2023
I am running this on M2, facing the same issue
dont know what to do?
njmulsqb commentedon Jan 16, 2023
I resolved the issue by ditching homebrew and following the ruby installation docs provided on Jekyll site
Hazel233 commentedon Aug 25, 2023
This really helps after searching for a lot methods.
haberman commentedon Aug 28, 2023
Protobuf is releasing with arm64-darwin binary gems. For example, here is the latest one: https://rubygems.org/gems/google-protobuf/versions/3.24.2-arm64-darwin
However, the current gems require Ruby >=2.7, and I believe macOS is still shipping with Ruby 2.6.
So to use the current version of the protobuf package, you would need to install a separate Ruby from Homebrew (or from source).