Home > Mobile >  Gem 'ruby-jq' compilation error by Apple M1 (ARM) chip
Gem 'ruby-jq' compilation error by Apple M1 (ARM) chip

Time:08-31

I'm trying to bundle install Sinatra project with gem 'ruby-jq'. As I found out it works on Macs with Intel chips. My Apple M1 Max chip result:

➜  my_service git:(develop) ✗ bundle install
Warning: the running version of Bundler (2.2.22) is older than the version that created the lockfile (2.3.13). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.3.13`.
Fetching gem metadata from https://rubygems.org/
Fetching gem metadata from https://rubygems.org/.........
Using rake 13.0.6
...
Using bundler 2.2.22
...
Fetching ruby-jq 0.2.1
...
Installing ruby-jq 0.2.1 with native extensions
...
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/ruby-jq-0.2.1/ext
/Users/Sergey.Kovalov/.rvm/rubies/ruby-3.0.2/bin/ruby -I /Users/Sergey.Kovalov/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0 -r ./siteconf20220826-74763-mnprea.rb extconf.rb
Buildling jq using packaged libraries.
Downloading jq-1.6.tar.gz 
...
Downloading jq-1.6.tar.gz 
Extracting jq-1.6.tar.gz into tmp/arm64-apple-darwin21.6.0/ports/jq/1.6... OK
Running 'autoreconf' for jq 1.6... OK
Running 'configure' for jq 1.6... OK
Running 'compile' for jq 1.6... ERROR, review '/Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/ruby-jq-0.2.1/ext/tmp/arm64-apple-darwin21.6.0/ports/jq/1.6/compile.log' to see what happened. Last lines are:
========================================================================
  GEN      src/builtin.inc
fatal: not a git repository (or any of the parent directories): .git
  GEN      src/version.h
fatal: not a git repository (or any of the parent directories): .git
/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-recursive
Making all in modules/oniguruma
make[2]: *** No rule to make target `all'.  Stop.
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
========================================================================
*** 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/Sergey.Kovalov/.rvm/rubies/ruby-3.0.2/bin/$(RUBY_BASE_NAME)
    --use-system-libraries
/Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/mini_portile2-2.8.0/lib/mini_portile2/mini_portile.rb:460:in `block in execute': Failed to complete compile task (RuntimeError)
    from /Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/mini_portile2-2.8.0/lib/mini_portile2/mini_portile.rb:426:in `chdir'
    from /Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/mini_portile2-2.8.0/lib/mini_portile2/mini_portile.rb:426:in `execute'
    from /Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/mini_portile2-2.8.0/lib/mini_portile2/mini_portile.rb:144:in `compile'
    from /Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/mini_portile2-2.8.0/lib/mini_portile2/mini_portile.rb:187:in `cook'
    from extconf.rb:27:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/ruby-jq-0.2.1 for inspection.
Results logged to /Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/extensions/arm64-darwin-21/3.0.0/ruby-jq-0.2.1/gem_make.out

An error occurred while installing ruby-jq (0.2.1), and Bundler cannot continue.
Make sure that `gem install ruby-jq -v '0.2.1' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  ruby-jq

**********

➜  my_service git:(develop) ✗ gem install ruby-jq -v '0.2.1' --source 'https://rubygems.org/'
Building native extensions. This could take a while...
ERROR:  Error installing ruby-jq:
    ERROR: Failed to build gem native extension.

    current directory: /Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/ruby-jq-0.2.1/ext
/Users/Sergey.Kovalov/.rvm/rubies/ruby-3.0.2/bin/ruby -I /Users/Sergey.Kovalov/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0 -r ./siteconf20220826-78454-9gmb3t.rb extconf.rb
Buildling jq using packaged libraries.
Downloading jq-1.6.tar.gz 
Extracting jq-1.6.tar.gz into tmp/arm64-apple-darwin21.6.0/ports/jq/1.6... OK
Running 'autoreconf' for jq 1.6... OK
Running 'configure' for jq 1.6... OK
Running 'compile' for jq 1.6... ERROR, review '/Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/ruby-jq-0.2.1/ext/tmp/arm64-apple-darwin21.6.0/ports/jq/1.6/compile.log' to see what happened. Last lines are:
========================================================================
  GEN      src/builtin.inc
fatal: not a git repository (or any of the parent directories): .git
  GEN      src/version.h
fatal: not a git repository (or any of the parent directories): .git
/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-recursive
Making all in modules/oniguruma
make[2]: *** No rule to make target `all'.  Stop.
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
========================================================================
*** 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/Sergey.Kovalov/.rvm/rubies/ruby-3.0.2/bin/$(RUBY_BASE_NAME)
    --use-system-libraries
/Users/Sergey.Kovalov/.rvm/rubies/ruby-3.0.2/lib/ruby/gems/3.0.0/gems/mini_portile2-2.8.0/lib/mini_portile2/mini_portile.rb:460:in `block in execute': Failed to complete compile task (RuntimeError)
    from /Users/Sergey.Kovalov/.rvm/rubies/ruby-3.0.2/lib/ruby/gems/3.0.0/gems/mini_portile2-2.8.0/lib/mini_portile2/mini_portile.rb:426:in `chdir'
    from /Users/Sergey.Kovalov/.rvm/rubies/ruby-3.0.2/lib/ruby/gems/3.0.0/gems/mini_portile2-2.8.0/lib/mini_portile2/mini_portile.rb:426:in `execute'
    from /Users/Sergey.Kovalov/.rvm/rubies/ruby-3.0.2/lib/ruby/gems/3.0.0/gems/mini_portile2-2.8.0/lib/mini_portile2/mini_portile.rb:144:in `compile'
    from /Users/Sergey.Kovalov/.rvm/rubies/ruby-3.0.2/lib/ruby/gems/3.0.0/gems/mini_portile2-2.8.0/lib/mini_portile2/mini_portile.rb:187:in `cook'
    from extconf.rb:27:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/ruby-jq-0.2.1 for inspection.
Results logged to /Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/extensions/arm64-darwin-21/3.0.0/ruby-jq-0.2.1/gem_make.out

gem_make.out file content:

current directory: /Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/ruby-jq-0.2.1/ext
/Users/Sergey.Kovalov/.rvm/rubies/ruby-3.0.2/bin/ruby -I /Users/Sergey.Kovalov/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0 -r ./siteconf20220826-82776-3jn351.rb extconf.rb
Buildling jq using packaged libraries.

Downloading jq-1.6.tar.gz (  0%) 
...
Downloading jq-1.6.tar.gz (100%) 
Extracting jq-1.6.tar.gz into tmp/arm64-apple-darwin21.6.0/ports/jq/1.6... OK
Running 'autoreconf' for jq 1.6... OK
Running 'configure' for jq 1.6... OK
Running 'compile' for jq 1.6... ERROR, review '/Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/ruby-jq-0.2.1/ext/tmp/arm64-apple-darwin21.6.0/ports/jq/1.6/compile.log' to see what happened. Last lines are:
========================================================================
  GEN      src/builtin.inc
fatal: not a git repository (or any of the parent directories): .git
  GEN      src/version.h
fatal: not a git repository (or any of the parent directories): .git
/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-recursive
Making all in modules/oniguruma
make[2]: *** No rule to make target `all'.  Stop.
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
========================================================================
*** 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/Sergey.Kovalov/.rvm/rubies/ruby-3.0.2/bin/$(RUBY_BASE_NAME)
    --use-system-libraries
/Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/mini_portile2-2.8.0/lib/mini_portile2/mini_portile.rb:460:in `block in execute': Failed to complete compile task (RuntimeError)
    from /Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/mini_portile2-2.8.0/lib/mini_portile2/mini_portile.rb:426:in `chdir'
    from /Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/mini_portile2-2.8.0/lib/mini_portile2/mini_portile.rb:426:in `execute'
    from /Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/mini_portile2-2.8.0/lib/mini_portile2/mini_portile.rb:144:in `compile'
    from /Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2/gems/mini_portile2-2.8.0/lib/mini_portile2/mini_portile.rb:187:in `cook'
    from extconf.rb:27:in `<main>'

extconf failed, exit code 1

I've also tried different installation options and varieties such as:

RUBYJQ_USE_SYSTEM_LIBRARIES=true gem install ruby-jq -v '0.2.1'
***
arch -x86_64 gem install ruby-jq -v '0.2.1' --source 'https://rubygems.org/'
***
bundle config --global build.ruby-jq --use-system-libraries --with-jqlib=/opt/homebrew/lib/
***
bundle config --global build.ruby-jq --use-system-libraries --with-jq-dir=/opt/homebrew/bin/jq

Info from my laptop:

➜  my_service git:(develop) ✗ rvm list
=* ruby-3.0.2 [ arm64 ]

# => - current
# =* - current && default
#  * - default
***
➜  my_service git:(develop) ✗ echo $GEM_HOME
/Users/Sergey.Kovalov/.rvm/gems/ruby-3.0.2

➜  my_service git:(develop) ✗ jq --version
jq-1.6
***
➜  my_service git:(develop) ✗ which jq
/opt/homebrew/bin/jq
***
➜  my_service git:(develop) ✗ ls -lah /opt/homebrew/lib/ | grep -i libjq
lrwxr-xr-x   1 Sergey.Kovalov  admin    34B 25 Aug 09:45 libjq.1.dylib -> ../Cellar/jq/1.6/lib/libjq.1.dylib
lrwxr-xr-x   1 Sergey.Kovalov  admin    28B 25 Aug 09:45 libjq.a -> ../Cellar/jq/1.6/lib/libjq.a
lrwxr-xr-x   1 Sergey.Kovalov  admin    32B 25 Aug 09:45 libjq.dylib -> ../Cellar/jq/1.6/lib/libjq.dylib

BTW, cloning gem origin repo to local machine and set the path in Gemfile as gem 'ruby-jq', path: '/Users/Sergey.Kovalov/work/ruby-jq' works and bundle install is completed successfully.

The point is to complete bundle install with the https://rubygems.org/gems/ruby-jq/ source. Please advise or tell how did you solve this issue.

CodePudding user response:

One colleague from online-school provided the right parameters how to set bundle config:

brew install jq
bundle config set build.ruby-jq --use-system-libraries --with-jq-dir=$(brew --prefix jq)
bundle install

Verified on Apple M1 Max chip:

➜  my_service git:(develop) ✗ ruby -v
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [arm64-darwin21]
➜  my_service git:(develop) ✗ jq --version
jq-1.6
  • Related