rubyjs / libv8-node

Package libv8 from Node
MIT License
14 stars 27 forks source link

Add Darwin ARM target #14

Closed lloeki closed 3 years ago

lloeki commented 4 years ago
vseguin commented 3 years ago

Hey @lloeki ! Great to see this being worked on, do you have an idea when this could be released? We use sqreen as a dependency in our app and for new developers with Apple M1 chips we have to comment it out for now.

lloeki commented 3 years ago

@vseguin I released a build based on node 15.5.1 just yesterday, sq_mini_racer 0.3.1.0.3 and Sqreen should just work now on M1.

vseguin commented 3 years ago

@lloeki is it pushed to rubygems? I get

  ERROR: found gems matching libv8-node:'~> 15.5.1.0.beta1', but no binary for -darwin-20
         try "gem install libv8-node:'~> 15.5.1.0.beta1'" to attempt to build libv8-node from source

I bumped sqreen to 1.23.0 - which seems to resolve to sq_mini_racer 0.3.1.03.

lloeki commented 3 years ago

I suppose you're trying to use macOS's own Ruby, which you can check with ruby -e 'puts RUBY_PLATFORM' or ruby -e 'p Gem.platforms'. Unfortunately this Apple-provided Ruby is built as arm64e, and currently libv8 builds as arm64.

I encourage you to try installing your own Ruby e.g. through rbenv install.

vseguin commented 3 years ago

@lloeki so hum sorry to come back on this, but I confirmed I am on rbenv's Ruby 2.7.1

ruby -e 'p Gem.platforms'
["ruby", #<Gem::Platform:0x000000014d0bf880 @cpu="", @os="darwin", @version="20" @cpu="", @os="darwin", @version="20">]

ruby -e 'puts RUBY_PLATFORM' 
-darwin20

I tried this and it seems that's it's only "-darwin20", no arm64 or arm64e?

lloeki commented 3 years ago

@vseguin Can you run file or lipo on it?

Examples:

$ lipo -info /usr/bin/ruby 
Architectures in the fat file: /usr/bin/ruby are: x86_64 arm64e 
$ lipo -info ~/.rbenv/versions/2.7.2/bin/ruby
Non-fat file: /Users/lloeki/.rbenv/versions/2.7.2/bin/ruby is architecture: x86_64
sweetppro commented 3 years ago

Im also having issues installing on my M1 MacBook Air... here's my setup:

me % ruby -e 'p Gem.platforms'
["ruby", #<Gem::Platform:0x000000013f020d88 @cpu="", @os="darwin", @version="20">]
me % ruby -e 'puts RUBY_PLATFORM'
-darwin20
me % lipo -info /usr/bin/ruby 
Architectures in the fat file: /usr/bin/ruby are: x86_64 arm64e 
me % lipo -info ~/.rbenv/versions/2.6.5/bin/ruby
Non-fat file: /Users/mrqwirk/.rbenv/versions/2.6.5/bin/ruby is architecture: arm64

and the error:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/me/myapp/gems/ruby/2.6.0/gems/sq_mini_racer-0.3.1.0.3/ext/mini_racer_extension
/Users/me/.rbenv/versions/2.6.5/bin/ruby -I /Users/me/.rbenv/versions/2.6.5/lib/ruby/site_ruby/2.6.0 -r ./siteconf20210128-7070-s9t894.rb extconf.rb
  ERROR: found gems matching libv8-node:'~> 15.5.1.0.beta1', but no binary for -darwin-20
         try "gem install libv8-node:'~> 15.5.1.0.beta1'" to attempt to build libv8-node from source
*** 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/me/.rbenv/versions/2.6.5/bin/$(RUBY_BASE_NAME)
platform ruby:-darwin20 rubygems:-darwin-20 detected:-darwin-20
looking for libv8-node-*--darwin-20 in ["/Users/me/myapp/gems/ruby/2.6.0"]
libv8-node-*--darwin-20 not found in ["/Users/me/myapp/gems/ruby/2.6.0"]
looking for libv8-node-*--darwin-20 in ["/Users/me/myapp/gems/ruby/2.6.0/gems/sq_mini_racer-0.3.1.0.3/ext/mini_racer_extension/vendor"]
libv8-node-*--darwin-20 not found in ["/Users/me/myapp/gems/ruby/2.6.0/gems/sq_mini_racer-0.3.1.0.3/ext/mini_racer_extension/vendor"]

extconf failed, exit code 1
lloeki commented 3 years ago

Looks like the same deal: platform ruby:-darwin20 rubygems:-darwin-20 detected:-darwin-20

This is output straight from Ruby's RUBY_PLATFORM and Gem::Platform.local, so it's Ruby itself that's hosed right there.

I see you're running 2.6.x in rbenv. Unfortunately as far as I can tell Ruby 2.7.x is the first Ruby version supporting arm64-darwin, that could very well explain why 2.6.x has a broken RUBY_PLATFORM.

Indeed, there's ruby/ruby@f46929833923d96e4dc706945fd537a1caaebe66 where you can read the following items:

  • Fix build error on Apple silicon macOS
  • Extract correct processor name for ARM64 Macs

And the patchset contains other important fixes for Apple Silicon (the desc is a bit obscured in the commit message, but there's important stuff regarding coroutines, without which you'd get seemingly random segfaults). It's apparently just followed by ruby/ruby@811b2b0df5e670ad8db7951191232ce3f5b0d978 which is the bump to 2.7.2.

Of course Apple provides their own 2.6 with a set of patches of their own, but it's heavily deprecated and doesn't contain some of the fixes above.

So my suggestion would be to stick to 2.7.2 and up on M1, unless you want to backport that patchset (at least, there may be more needed).

sweetppro commented 3 years ago

Ah, That’s an easy fix. Thanks for the heads up.

sweetppro commented 3 years ago

So my suggestion would be to stick to 2.7.2 and up on M1, unless you want to backport that patchset (at least, there may be more needed).

worked like a charm! many thanks

lloeki commented 3 years ago

Apple's Ruby 2.6 is not to be relied on. Truly universal builds are painful, and Apple's Ruby is the only instance of it.

Reports all around say it works fine for all non-Apple, non-universal >2.7.2 rubies.

No CI yet.