kubo / ruby-oci8

Ruby-oci8 - Oracle interface for ruby
Other
169 stars 75 forks source link

Issues during gem install with M1 running on Rosetta (Oracle instant client is not found. (RuntimeError)) #252

Closed quynhethereal closed 1 year ago

quynhethereal commented 1 year ago

Hi there,

First of all, thank you for your work. I'm currently having some issues with the gem installation that I hope you can provide some insights into.

I'm using a Mac M1 Pro 2021. I run my terminal under Rosetta (so the architecture is i386) as I know that there is no native version of Oracle's instant client yet. I'm using the official brew installation guide from Oracle to install the client, i.e:

brew tap InstantClientTap/instantclient
brew install instantclient-basic
brew install instantclient-sdk
brew install instantclient-sqlplus

Below are my environment configurations:

export OCI_DIR=/usr/local/homebrew/lib

The instant client is installed at path: /usr/local/Homebrew/Cellar image.

The OCI_DIR has these files: image

However, when I try to run the command gem install ruby-oci8 -v '2.2.11' I'm met with Oracle instant client is not found. (RuntimeError). Complete log is attached below:

current directory: /Users/quynhethereal/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.11/ext/oci8
/Users/quynhethereal/.rbenv/versions/2.7.4/bin/ruby -I /Users/quynhethereal/.rbenv/versions/2.7.4/lib/ruby/2.7.0 -r ./siteconf20230201-83581-jzbiv3.rb extconf.rb
attempting to locate oracle-instantclient...
checking load library path... 
  OCI_DIR... 
    checking /usr/local/homebrew/lib... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/quynhethereal/.rbenv/versions/2.7.4/bin/$(RUBY_BASE_NAME)
    --with-instant-client
    --without-instant-client
    --with-instant-client-dir
    --without-instant-client-dir
    --with-instant-client-include
    --without-instant-client-include=${instant-client-dir}/include
    --with-instant-client-lib
    --without-instant-client-lib=${instant-client-dir}/lib
/Users/quynhethereal/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.11/ext/oci8/oraconf.rb:507:in `guess_ic_dir': RuntimeError (RuntimeError)
    from /Users/quynhethereal/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.11/ext/oci8/oraconf.rb:257:in `get'
    from extconf.rb:22:in `<main>'
/Users/quynhethereal/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.11/ext/oci8/oraconf.rb:507:in `guess_ic_dir': Oracle instant client is not found. (RuntimeError)
You need to install Oracle instant client.
    from /Users/quynhethereal/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.11/ext/oci8/oraconf.rb:257:in `get'
    from extconf.rb:22:in `<main>'
  skip: /usr/local/Homebrew/lib/libclntsh.dylib.19.1 is for x86_64 cpu.
  checking the default value of DYLD_FALLBACK_LIBRARY_PATH...
    checking /Users/quynhethereal/lib... no
    checking /usr/local/lib... no
    checking /lib... no
    checking /usr/lib... no
---------------------------------------------------
Error Message:
  Oracle instant client is not found.
  You need to install Oracle instant client.

Backtrace:
  /Users/quynhethereal/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.11/ext/oci8/oraconf.rb:507:in `guess_ic_dir'
  /Users/quynhethereal/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.11/ext/oci8/oraconf.rb:257:in `get'
  extconf.rb:22:in `<main>'
---------------------------------------------------
See:
 * http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/install-full-client.md for Oracle full client
 * http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/install-instant-client.md for Oracle instant client
 * http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/install-on-osx.md for OS X
 * http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/report-installation-issue.md to report an issue.
extconf failed, exit code 1

I have traced into the source code of the error (https://github.com/kubo/ruby-oci8/blob/19c4341616550debfcf66e40ea6daf0831b24e7a/ext/oci8/oraconf.rb#L497-L510) and found that this error occurs when the program fails to find the files with glob #{oci_basename}.#{so_ext}#{oci_glob_postfix} (https://github.com/kubo/ruby-oci8/blob/19c4341616550debfcf66e40ea6daf0831b24e7a/ext/oci8/oraconf.rb#L451). It is quite weird to me as the files in the OCI_DIR matches the same pattern as the glob condition.

Can you share some insights on how to debug this issue? Thank you so much in advance.

kubo commented 1 year ago

Could you post the output of the following commands under Rosetta?

ruby -v
ruby -e "puts [nil].pack('P').size"
ruby -r etc -e "puts Etc.uname[:machine]"
uname -m
file `rbenv which ruby`

I guess that

  1. Your ruby isn't x86_64. So it cannot use Oracle instant client for x86_64. Otherwise,
  2. Your ruby is x86_64 but oraconf.rb guesses that it isn't x86_64 by mistake. So it rejects Oracle instant client for x86_64.
quynhethereal commented 1 year ago

Thanks @kubo. You are absolutely correct. I was using the arm-64 version of Ruby 2.7.4. After I switched to x86 version it is able to install the gem. Thank you very much for your support!

image
thiagoluppi commented 1 year ago

Thank you very much. I've been trying to install this gem on a M2 MBP for a while now.

elgartoinf commented 1 year ago

Thanks @kubo. You are absolutely correct. I was using the arm-64 version of Ruby 2.7.4. After I switched to x86 version it is able to install the gem. Thank you very much for your support! image

@quynhethereal How did you make the change?

quynhethereal commented 1 year ago

@elgartoinf In my case, I used Rosetta Terminal for the installation. You can double check that you are running the correct architecture by running arch command. It should output i386.

image

You can then use Homebrew to install rvm (a Ruby Version Manager or whatever VM you like) and install Ruby. Your Ruby version installed will be the x86 version. Double check by running ruby --version and see that it is the x86 one (rather than the arm64).

image