ianks / mini_phone

A fast phone number parser, validator and formatter for Ruby. This gem binds to Google's C++ libphonenumber for spec-compliance and performance.
MIT License
158 stars 7 forks source link

Can't install on apple silicon #9

Closed jmschneider closed 2 years ago

jmschneider commented 2 years ago

I just upgraded to a M1 Pro mac and I've been having trouble getting this to work. Homebrew installs libphonenumber fine but when I run bundle install I get the "It looks like libphonenumber is not installed on this system" message. I tried adding both of the following (one at a time) to my ~/.bundle/config to help it find the library:

BUNDLE_BUILD__MINI_PHONE: "--with-opt-dir=/opt/homebrew/opt/libphonenumber"
BUNDLE_BUILD__MINI_PHONE: "--with-phonenumber-dir=/opt/homebrew/opt/libphonenumber"

In both cases, I got the following:

current directory: /Users/username/.asdf/installs/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/mini_phone-1.1.7/ext/mini_phone
/Users/username/.asdf/installs/ruby/2.7.4/bin/ruby -I /Users/username/.asdf/installs/ruby/2.7.4/lib/ruby/2.7.0 -r ./siteconf20211027-46412-gqe3fb.rb extconf.rb --with-phonenumber-dir\=/opt/homebrew/opt/libphonenumber
checking for -lphonenumber... yes
creating Makefile

current directory: /Users/username/.asdf/installs/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/mini_phone-1.1.7/ext/mini_phone
make "DESTDIR=" clean

current directory: /Users/username/.asdf/installs/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/mini_phone-1.1.7/ext/mini_phone
make "DESTDIR="
compiling mini_phone.cc
In file included from mini_phone.cc:2:
/opt/homebrew/opt/libphonenumber/include/phonenumbers/phonemetadata.pb.h:10:10: fatal error: 'google/protobuf/port_def.inc' file not found
#include <google/protobuf/port_def.inc>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [mini_phone.o] Error 1

make failed, exit code 2
jmschneider commented 2 years ago

I was finally able to figure out a solution right after I created this issue. I updated my ~/.bundle/config to:

BUNDLE_BUILD__MINI_PHONE: "--with-phonenumber-dir=/opt/homebrew/opt/libphonenumber --with-opt-dir=/opt/homebrew/opt/protobuf"

I'm not super familiar with how ruby handles linking and stuff for native extensions so there may be a better way but that finally worked for me.

espen commented 2 years ago

I'm having the same issue. the build flags above did not help.

When using the build flags I get the following error: `In file included from mini_phone.cc:4: /opt/homebrew/opt/libphonenumber/include/phonenumbers/phonenumberutil.h:33:10: fatal error: 'absl/container/node_hash_set.h' file not found

include "absl/container/node_hash_set.h"`

jmschneider commented 2 years ago

@espen I was able to get mine working again by updating my ~/.bundle/config to be:

BUNDLE_BUILD__MINI_PHONE: "--with-phonenumber-dir=/opt/homebrew/opt/libphonenumber --with-opt-dir=/opt/homebrew/opt/protobuf:/opt/homebrew/opt/abseil"

It would be nice if it just worked out of the box but hopefully that can at least get you up and running.

ianks commented 2 years ago

Fixed in v1.1.8 ❤️

espen commented 1 year ago

I ran into this again when upgrading my Ruby installation. I am able to uninstall and reinstall mini_phone on Ruby 3.1.2, but not able to install it on 3.1.3. I get an error: "Undefined symbols for architecture arm64:".

~ $ asdf shell ruby 3.1.2
~ $ gem list mini_phone

*** LOCAL GEMS ***

mini_phone (1.1.8)
~ $ gem install mini_phone
Building native extensions. This could take a while...
Successfully installed mini_phone-1.1.8
1 gem installed
~ $ gem uninstall mini_phone
Successfully uninstalled mini_phone-1.1.8
~ $ gem install mini_phone
Fetching mini_phone-1.1.8.gem
Building native extensions. This could take a while...
Successfully installed mini_phone-1.1.8
1 gem installed
~ $ asdf shell ruby 3.1.3
~ $ gem install mini_phone
Building native extensions. This could take a while...
ERROR:  Error installing mini_phone:
  ERROR: Failed to build gem native extension.

    current directory: .asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/mini_phone-1.1.8/ext/mini_phone
.asdf/installs/ruby/3.1.3/bin/ruby -I .asdf/installs/ruby/3.1.3/lib/ruby/3.1.0 extconf.rb
checking for -lphonenumber... yes
creating Makefile

current directory: .asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/mini_phone-1.1.8/ext/mini_phone
make DESTDIR\= sitearchdir\=./.gem.20221211-41922-ck0afm sitelibdir\=./.gem.20221211-41922-ck0afm clean

current directory: .asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/mini_phone-1.1.8/ext/mini_phone
make DESTDIR\= sitearchdir\=./.gem.20221211-41922-ck0afm sitelibdir\=./.gem.20221211-41922-ck0afm
compiling mini_phone.cc
linking shared-object mini_phone/mini_phone.bundle
Undefined symbols for architecture arm64:
  "google::protobuf::internal::LogMessage::LogMessage(google::protobuf::LogLevel, char const*, int)", referenced from:
      void google::protobuf::internal::RepeatedPtrFieldBase::MergeFrom<google::protobuf::RepeatedPtrField<i18n::phonenumbers::NumberFormat>::TypeHandler>(google::protobuf::internal::RepeatedPtrFieldBase const&) in mini_phone.o
  "google::protobuf::internal::LogMessage::~LogMessage()", referenced from:
      void google::protobuf::internal::RepeatedPtrFieldBase::MergeFrom<google::protobuf::RepeatedPtrField<i18n::phonenumbers::NumberFormat>::TypeHandler>(google::protobuf::internal::RepeatedPtrFieldBase const&) in mini_phone.o
  "google::protobuf::internal::LogMessage::operator<<(char const*)", referenced from:
      void google::protobuf::internal::RepeatedPtrFieldBase::MergeFrom<google::protobuf::RepeatedPtrField<i18n::phonenumbers::NumberFormat>::TypeHandler>(google::protobuf::internal::RepeatedPtrFieldBase const&) in mini_phone.o
  "google::protobuf::internal::GenericSwap(google::protobuf::MessageLite*, google::protobuf::MessageLite*)", referenced from:
      i18n::phonenumbers::PhoneNumber::Swap(i18n::phonenumbers::PhoneNumber*) in mini_phone.o
  "google::protobuf::internal::LogFinisher::operator=(google::protobuf::internal::LogMessage&)", referenced from:
      void google::protobuf::internal::RepeatedPtrFieldBase::MergeFrom<google::protobuf::RepeatedPtrField<i18n::phonenumbers::NumberFormat>::TypeHandler>(google::protobuf::internal::RepeatedPtrFieldBase const&) in mini_phone.o
  "google::protobuf::internal::ArenaStringPtr::Set(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, google::protobuf::Arena*)", referenced from:
      google::protobuf::internal::ArenaStringPtr::Set(char const*, google::protobuf::Arena*) in mini_phone.o
  "google::protobuf::internal::RepeatedPtrFieldBase::DestroyProtos()", referenced from:
      google::protobuf::RepeatedPtrField<i18n::phonenumbers::NumberFormat>::~RepeatedPtrField() in mini_phone.o
  "google::protobuf::internal::RepeatedPtrFieldBase::InternalExtend(int)", referenced from:
      google::protobuf::internal::RepeatedPtrFieldBase::MergeFromInternal(google::protobuf::internal::RepeatedPtrFieldBase const&, void (google::protobuf::internal::RepeatedPtrFieldBase::*)(void**, void**, int, int)) in mini_phone.o
  "google::protobuf::internal::RepeatedPtrFieldBase::AddOutOfLineHelper(void*)", referenced from:
      google::protobuf::RepeatedPtrField<i18n::phonenumbers::NumberFormat>::TypeHandler::Type* google::protobuf::internal::RepeatedPtrFieldBase::Add<google::protobuf::RepeatedPtrField<i18n::phonenumbers::NumberFormat>::TypeHandler>(google::protobuf::RepeatedPtrField<i18n::phonenumbers::NumberFormat>::TypeHandler::Type const*) in mini_phone.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mini_phone.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in .asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/mini_phone-1.1.8 for inspection.
Results logged to .asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/extensions/arm64-darwin-22/3.1.0/mini_phone-1.1.8/gem_make.out
espen commented 1 year ago

This seems to be a different issue so I created https://github.com/ianks/mini_phone/issues/13