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

Use brew install cocoapods instead of arch -x86_64 pod install on M1 MacBook #3003

Closed
bangseongbeom opened this issue Mar 10, 2022 · 12 comments

Comments

@bangseongbeom
Copy link

To solve the pod install issue on the M1 MacBook, #2974 suggests arch -x86_64 pod install command. You can also find it in a CocoaPods issue.

However, this approach is inappropriate. You may receive the following warnings when you run arch -x86_64 pod install:

facebook/react-native#33017

[!] Do not use "pod install" from inside Rosetta2 (x86_64 emulation on arm64).

[!] - Emulated x86_64 is slower than native arm64

[!] - May result in mixed architectures in rubygems (eg: ffi_c.bundle files may be x86_64 with an arm64 interpreter)

[!] Run "env /usr/bin/arch -arm64 /bin/bash --login" then try again.

This is a Ruby problem built in macOS. The built-in Ruby has been deprecated since Catalina (10.15), so you'll have to find another way.

Solution

brew install cocoapods internally downloads a Ruby suitable for the M1 MacBook.

The whole method I'd like to suggest is:

  1. brew install cocoapods
  2. pod install

instead of:

  1. sudo gem install cocoapods
  2. sudo arch -x86_64 gem install ffi
  3. arch -x86_64 pod install

See also

@cortinico
Copy link
Contributor

@cipolleschi What's your take here?

brew install cocoapods internally downloads a Ruby suitable for the M1 MacBook.

IMHO relying on brew for this sounds "risky", mostly because we have the .rubyversion file (https://github.com/facebook/react-native/blob/main/template/_ruby-version) and all the other machinery to handle the proper ruby/cocoapods version. It seems weird that we can't use them and rely on brew giving us a "good" version of cocoapods for M1.

cortinico referenced this issue in facebook/react-native Mar 10, 2022
Summary:
This Diff updates the RNTester README to support Mac M1 laptops.

## Changelog
[General][Changed] - Updated `rn-tester/README.md` to include instructions for Mac M1 users

Reviewed By: cortinico

Differential Revision: D34376951

fbshipit-source-id: 7195bddefb6e202261fef9b5f5225484c506fd9b
@danilobuerger
Copy link
Contributor

Could the instructions be for an older version of ffi? Afaik ffi supports arm64. It seems to me that those steps are no longer required and installing via bundler should just be it.

@cipolleschi
Copy link
Contributor

Hi everyone!
Having a look at ffi changelog it looks like that, starting from version 1.15.1, they are supporting arm64, as @danilobuerger was saying.

I propose that we update the doc for M1 users specifying that, if they encounter issues, they should update the ffi gem to at least that minimum version. What do you think @danilobuerger, @bangseongbeom, @cortinico?

@cortinico
Copy link
Contributor

Seems great to me 👍

@bangseongbeom
Copy link
Author

bangseongbeom commented Mar 24, 2022

@danilobuerger @cipolleschi the Apple ARM CPU patch on ffi version 1.15.1 won't work well on M1 MacBook's system Ruby. ffi filters CPU architecture via rbconfig, but the rbconfig on the system Ruby provides incorrect CPU arch information ("host_cpu" and "host" as "x86_64" and "x86_64-apple-darwin21").

You can find your rbconfig information with the following code (excerpted from Martin Albrecht):

(Make sure you are using system Ruby before running this script.)

ruby -e 'require "rbconfig"; pp RbConfig::CONFIG' | grep "host"

My result:

 "host_os"=>"darwin21",
 "host_vendor"=>"apple",
 "host_cpu"=>"x86_64",
 "host"=>"x86_64-apple-darwin21",
 "host_alias"=>"",

@danilobuerger
Copy link
Contributor

Starting with rn 0.68, we are expecting a ruby version of 2.7.4 as set in the Gemfile and .ruby-version. Thats not the ruby shipped from apple anyway.

@bangseongbeom
Copy link
Author

@danilobuerger Hmm... then we'll need to modify these paragraphs later.

https://reactnative.dev/docs/environment-setup#cocoapods

CocoaPods is built with Ruby and it will be installable with the default Ruby available on macOS. You can use a Ruby Version manager, however we recommend that you use the standard Ruby available on macOS unless you know what you're doing.

sudo gem install cocoapods

@cortinico
Copy link
Contributor

@danilobuerger Hmm... then we'll need to modify these paragraphs later.

That's correct. The recommendation would be to use bundler in the near future as it allows us to reduce the variability of ruby/cocoapods versions. The new app template comes with all the necessary files in place and the docs should be updated to reflect this.

@bangseongbeom
Copy link
Author

bangseongbeom commented Mar 25, 2022

Thanks for the detailed explanation! I close this issue as it will be resolved in the near future.

@javvadigithub
Copy link

This works for me :)
brew install cocoapods
pod install

@madilekci-avena
Copy link

This worked for me on m1 pro Ventura, thanks

@rahulpunchh
Copy link

Worked For me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants