cotag / http-parser

A super fast http parser for ruby
MIT License
18 stars 17 forks source link

/lib/ruby/gems/2.7.0/gems/http-parser-1.2.2/ext/arm-darwin/libhttp-parser-ext.bundle: mach-o, but wrong architecture #12

Open rgaufman opened 3 years ago

rgaufman commented 3 years ago

I've created a simple script:

require 'json'
require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'http'
end

response = HTTP.post('http://example.com', json: nil)

When I run it on MacBook 2020 M1 (Apple Silicon), I see:

Traceback (most recent call last):
    24: from test-http-arse.rb:8:in `<main>'
    23: from /opt/homebrew/Cellar/ruby/2.7.2/lib/ruby/2.7.0/bundler/inline.rb:54:in `gemfile'
    22: from /opt/homebrew/Cellar/ruby/2.7.2/lib/ruby/2.7.0/bundler/settings.rb:124:in `temporary'
    21: from /opt/homebrew/Cellar/ruby/2.7.2/lib/ruby/2.7.0/bundler/inline.rb:70:in `block in gemfile'
    20: from /opt/homebrew/Cellar/ruby/2.7.2/lib/ruby/2.7.0/bundler/runtime.rb:58:in `require'
    19: from /opt/homebrew/Cellar/ruby/2.7.2/lib/ruby/2.7.0/bundler/runtime.rb:58:in `each'
    18: from /opt/homebrew/Cellar/ruby/2.7.2/lib/ruby/2.7.0/bundler/runtime.rb:69:in `block in require'
    17: from /opt/homebrew/Cellar/ruby/2.7.2/lib/ruby/2.7.0/bundler/runtime.rb:69:in `each'
    16: from /opt/homebrew/Cellar/ruby/2.7.2/lib/ruby/2.7.0/bundler/runtime.rb:74:in `block (2 levels) in require'
    15: from /opt/homebrew/Cellar/ruby/2.7.2/lib/ruby/2.7.0/bundler/runtime.rb:74:in `require'
    14: from /opt/homebrew/lib/ruby/gems/2.7.0/gems/http-4.4.1/lib/http.rb:8:in `<top (required)>'
    13: from /opt/homebrew/lib/ruby/gems/2.7.0/gems/http-4.4.1/lib/http.rb:8:in `require'
    12: from /opt/homebrew/lib/ruby/gems/2.7.0/gems/http-4.4.1/lib/http/client.rb:9:in `<top (required)>'
    11: from /opt/homebrew/lib/ruby/gems/2.7.0/gems/http-4.4.1/lib/http/client.rb:9:in `require'
    10: from /opt/homebrew/lib/ruby/gems/2.7.0/gems/http-4.4.1/lib/http/connection.rb:6:in `<top (required)>'
     9: from /opt/homebrew/lib/ruby/gems/2.7.0/gems/http-4.4.1/lib/http/connection.rb:6:in `require'
     8: from /opt/homebrew/lib/ruby/gems/2.7.0/gems/http-4.4.1/lib/http/response/parser.rb:3:in `<top (required)>'
     7: from /opt/homebrew/lib/ruby/gems/2.7.0/gems/http-4.4.1/lib/http/response/parser.rb:3:in `require'
     6: from /opt/homebrew/lib/ruby/gems/2.7.0/gems/http-parser-1.2.2/lib/http-parser.rb:5:in `<top (required)>'
     5: from /opt/homebrew/lib/ruby/gems/2.7.0/gems/http-parser-1.2.2/lib/http-parser.rb:5:in `require'
     4: from /opt/homebrew/lib/ruby/gems/2.7.0/gems/http-parser-1.2.2/lib/http-parser/ext.rb:6:in `<top (required)>'
     3: from /opt/homebrew/lib/ruby/gems/2.7.0/gems/http-parser-1.2.2/lib/http-parser/ext.rb:8:in `<module:HttpParser>'
     2: from /opt/homebrew/lib/ruby/gems/2.7.0/gems/ffi-1.13.1/lib/ffi/library.rb:99:in `ffi_lib'
     1: from /opt/homebrew/lib/ruby/gems/2.7.0/gems/ffi-1.13.1/lib/ffi/library.rb:99:in `map'
/opt/homebrew/lib/ruby/gems/2.7.0/gems/ffi-1.13.1/lib/ffi/library.rb:145:in `block in ffi_lib': Could not open library '/opt/homebrew/lib/ruby/gems/2.7.0/gems/http-parser-1.2.2/ext/arm-darwin/libhttp-parser-ext.bundle': dlopen(/opt/homebrew/lib/ruby/gems/2.7.0/gems/http-parser-1.2.2/ext/arm-darwin/libhttp-parser-ext.bundle, 5): no suitable image found.  Did find: (LoadError)
    /opt/homebrew/lib/ruby/gems/2.7.0/gems/http-parser-1.2.2/ext/arm-darwin/libhttp-parser-ext.bundle: mach-o, but wrong architecture
    /opt/homebrew/lib/ruby/gems/2.7.0/gems/http-parser-1.2.2/ext/arm-darwin/libhttp-parser-ext.bundle: stat() failed with errno=25

Any ideas?

TheMlok commented 3 years ago

We have it like a dependency in Rails application, please any solution how to run it on M1?

stevehodgkiss commented 3 years ago

There's an open PR to address this issue https://github.com/cotag/http-parser/pull/10

DaniG2k commented 3 years ago

I'm having a similar problem on a Rails 5.0.7.2 app. Tried installing http-parser 1.2.2 but I get the same message 🤔 :

LoadError: Could not open library '/Users/danig2k/.rvm/gems/ruby-2.6.6/gems/http-parser-1.2.2/ext/aarch64-darwin/libhttp-parser-ext.bundle': dlopen(/Users/danig2k/.rvm/gems/ruby-2.6.6/gems/http-parser-1.2.2/ext/aarch64-darwin/libhttp-parser-ext.bundle, 5): no suitable image found.  Did find:
    /Users/danig2k/.rvm/gems/ruby-2.6.6/gems/http-parser-1.2.2/ext/aarch64-darwin/libhttp-parser-ext.bundle: mach-o, but wrong architecture
    /Users/danig2k/.rvm/gems/ruby-2.6.6/gems/http-parser-1.2.2/ext/aarch64-darwin/libhttp-parser-ext.bundle: stat() failed with errno=25

I believe the http gem is the one requiring http-parser.

rgaufman commented 3 years ago

http-parser is a dependency of httbrb for us. Our solution was to switch to faraday which removed this dependency.

stevenjohn commented 3 years ago

Hi there,

I'm on Apple Silicon and getting the same error as @rgaufman

Building native extensions. This could take a while...
ERROR:  Error installing http-parser:
    ERROR: Failed to build gem native extension.

    current directory: /Users/steve/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/http-parser-1.2.3/ext
/Users/steve/.rbenv/versions/2.6.6/bin/ruby -rrubygems /Users/steve/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/exe/rake RUBYARCHDIR\=/Users/steve/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/extensions/-darwin-20/2.6.0/http-parser-1.2.3 RUBYLIBDIR\=/Users/steve/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/extensions/-darwin-20/2.6.0/http-parser-1.2.3
rake aborted!
LoadError: dlopen(/Users/steve/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/ffi-1.14.2/lib/ffi_c.bundle, 9): no suitable image found.  Did find:
    /Users/steve/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/ffi-1.14.2/lib/ffi_c.bundle: mach-o, but wrong architecture
    /Users/steve/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/ffi-1.14.2/lib/ffi_c.bundle: mach-o, but wrong architecture - /Users/steve/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/ffi-1.14.2/lib/ffi_c.bundle

Caused by:
LoadError: cannot load such file -- 2.6/ffi_c

Caused by:
LoadError: cannot load such file -- ffi-compiler/compile_task

(See full trace by running task with --trace)

rake failed, exit code 1

Gem files will remain installed in /Users/steve/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/http-parser-1.2.3 for inspection.
Results logged to /Users/steve/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/extensions/-darwin-20/2.6.0/http-parser-1.2.3/gem_make.out

I'm installing v 1.2.3 and I'm confused as it looks like the PR to fix the m1 chip issue was merged?

Any ideas how I get http-parser to install correctly?

Many thanks, Steve.

nitrnitr commented 3 years ago

Fixing the http-version on the Gemfile did it for me, new version has this fixed

gem 'http-parser', '~> 1.2.3'

rstammer commented 2 years ago

Unfortunately, for Ruby 2.7.x, I still do face the issue when trying to gem install http-parser -v '1.2.3', so what @nitrnitr described does not apply to my situation so far.

Here's the error log:

LoadError: dlopen(/Users/robinstammer/.rvm/gems/ruby-2.7.4/gems/ffi-1.15.4/lib/ffi_c.bundle, 9): no suitable image found.  Did find:
    /Users/robinstammer/.rvm/gems/ruby-2.7.4/gems/ffi-1.15.4/lib/ffi_c.bundle: mach-o, but wrong architecture
    /Users/robinstammer/.rvm/gems/ruby-2.7.4/gems/ffi-1.15.4/lib/ffi_c.bundle: mach-o, but wrong architecture - /Users/robinstammer/.rvm/gems/ruby-2.7.4/gems/ffi-1.15.4/lib/ffi_c.bundle
/Users/robinstammer/.rvm/gems/ruby-2.7.4/gems/ffi-1.15.4/lib/ffi.rb:5:in `rescue in <top (required)>'
/Users/robinstammer/.rvm/gems/ruby-2.7.4/gems/ffi-1.15.4/lib/ffi.rb:2:in `<top (required)>'
/Users/robinstammer/.rvm/gems/ruby-2.7.4/gems/ffi-compiler-1.0.1/lib/ffi-compiler/compile_task.rb:4:in `<top (required)>'
/Users/robinstammer/.rvm/gems/ruby-2.7.4/gems/http-parser-1.2.3/ext/Rakefile:1:in `<top (required)>'
/Users/robinstammer/.rvm/gems/ruby-2.7.4/gems/rake-13.0.6/exe/rake:27:in `<main>'

Caused by:
LoadError: cannot load such file -- 2.7/ffi_c
/Users/robinstammer/.rvm/gems/ruby-2.7.4/gems/ffi-1.15.4/lib/ffi.rb:3:in `<top (required)>'
/Users/robinstammer/.rvm/gems/ruby-2.7.4/gems/ffi-compiler-1.0.1/lib/ffi-compiler/compile_task.rb:4:in `<top (required)>'
/Users/robinstammer/.rvm/gems/ruby-2.7.4/gems/http-parser-1.2.3/ext/Rakefile:1:in `<top (required)>'
/Users/robinstammer/.rvm/gems/ruby-2.7.4/gems/rake-13.0.6/exe/rake:27:in `<main>'

Caused by:
LoadError: cannot load such file -- ffi-compiler/compile_task
/Users/robinstammer/.rvm/gems/ruby-2.7.4/gems/http-parser-1.2.3/ext/Rakefile:1:in `<top (required)>'
/Users/robinstammer/.rvm/gems/ruby-2.7.4/gems/rake-13.0.6/exe/rake:27:in `<main>'
(See full trace by running task with --trace)

rake failed, exit code 1

Any ideas?

ryanstuhl805 commented 2 years ago

Similar output happening with a non M1 machine recently updated to Mac OS Monterey.

Installing llhttp-ffi 0.4.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/snip/Git/admin/.bundle/ruby/2.7.0/gems/llhttp-ffi-0.4.0/ext
/Users/snip/.rbenv/versions/2.7.4/bin/ruby -I/Users/snip/.rbenv/versions/2.7.4/lib/ruby/2.7.0/rubygems -rrubygems /Users/snip/Git/admin/.bundle/ruby/2.7.0/gems/rake-13.0.6/exe/rake
RUBYARCHDIR\=/Users/snip/Git/admin/.bundle/ruby/2.7.0/extensions/x86_64-darwin-20/2.7.0/llhttp-ffi-0.4.0 RUBYLIBDIR\=/Users/snip/Git/admin/.bundle/ruby/2.7.0/extensions/x86_64-darwin-20/2.7.0/llhttp-ffi-0.4.0
rake aborted!
LoadError: incompatible library version - /Users/snip/Git/admin/.bundle/ruby/2.7.0/extensions/x86_64-darwin-20/2.7.0/ffi-1.15.4/ffi_c.bundle
/Users/snip/Git/admin/.bundle/ruby/2.7.0/gems/ffi-1.15.4/lib/ffi.rb:5:in `rescue in <top (required)>'
/Users/snip/Git/admin/.bundle/ruby/2.7.0/gems/ffi-1.15.4/lib/ffi.rb:2:in `<top (required)>'
/Users/snip/Git/admin/.bundle/ruby/2.7.0/gems/ffi-compiler-1.0.1/lib/ffi-compiler/compile_task.rb:4:in `<top (required)>'
/Users/snip/Git/admin/.bundle/ruby/2.7.0/gems/llhttp-ffi-0.4.0/ext/Rakefile:3:in `<top (required)>'
/Users/snip/Git/admin/.bundle/ruby/2.7.0/gems/rake-13.0.6/exe/rake:27:in `<main>'

Caused by:
LoadError: cannot load such file -- 2.7/ffi_c
/Users/snip/Git/admin/.bundle/ruby/2.7.0/gems/ffi-1.15.4/lib/ffi.rb:3:in `<top (required)>'
/Users/snip/Git/admin/.bundle/ruby/2.7.0/gems/ffi-compiler-1.0.1/lib/ffi-compiler/compile_task.rb:4:in `<top (required)>'
/Users/snip/Git/admin/.bundle/ruby/2.7.0/gems/llhttp-ffi-0.4.0/ext/Rakefile:3:in `<top (required)>'
/Users/snip/Git/admin/.bundle/ruby/2.7.0/gems/rake-13.0.6/exe/rake:27:in `<main>'

Caused by:
LoadError: cannot load such file -- ffi-compiler/compile_task
/Users/snip/Git/admin/.bundle/ruby/2.7.0/gems/llhttp-ffi-0.4.0/ext/Rakefile:3:in `<top (required)>'
/Users/snip/Git/admin/.bundle/ruby/2.7.0/gems/rake-13.0.6/exe/rake:27:in `<main>'
(See full trace by running task with --trace)

An error occurred while installing llhttp-ffi (0.4.0), and Bundler cannot continue.

In Gemfile:
  noticed was resolved to 1.5.3, which depends on
    http was resolved to 5.0.4, which depends on
      llhttp-ffi