Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

libv8 fails to build on Catalina 10.15 #282

Closed
mikekytyzov opened this issue Oct 29, 2019 · 23 comments
Closed

libv8 fails to build on Catalina 10.15 #282

mikekytyzov opened this issue Oct 29, 2019 · 23 comments

Comments

@mikekytyzov
Copy link

mikekytyzov commented Oct 29, 2019

macos 10.15.1 Beta (19B86a)
gem version 3.16.14.19
x86_64-darwin19

Compiling v8 for x64
Using python 2.7.16
Using compiler: c++ (clang version 11.0.0)
Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
Beginning compilation. This will take some time.
Building v8 with env CXX=c++ LINK=c++  /usr/bin/make x64.release ARFLAGS.target=crs werror=no
GYP_GENERATORS=make \
	build/gyp/gyp --generator-output="out" build/all.gyp \
	              -Ibuild/standalone.gypi --depth=. \
	              -Dv8_target_arch=x64 \
	              -S.x64  -Dv8_enable_backtrace=1 -Dv8_can_use_vfp2_instructions=true -Darm_fpu=vfpv2 -Dv8_can_use_vfp3_instructions=true -Darm_fpu=vfpv3 -Dwerror=''
  CXX(target) /Users/mikhailkytyzov/bundle/ruby/2.6.0/gems/libv8-3.16.14.19/vendor/v8/out/x64.release/obj.target/preparser_lib/src/allocation.o
warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
In file included from ../src/allocation.cc:33:
../src/utils.h:33:10: fatal error: 'climits' file not found
#include <climits>
         ^~~~~~~~~
1 warning and 1 error generated.
make[1]: *** [/Users/mikhailkytyzov/bundle/ruby/2.6.0/gems/libv8-3.16.14.19/vendor/v8/out/x64.release/obj.target/preparser_lib/src/allocation.o] Error 1
make: *** [x64.release] Error 2
/Users/mikhailkytyzov/bundle/ruby/2.6.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:36:in `block in verify_installation!': libv8 did not install properly, expected binary v8 archive
'/Users/mikhailkytyzov/bundle/ruby/2.6.0/gems/libv8-3.16.14.19/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_base.a'to exist, but it was not found (Libv8::Location::Vendor::ArchiveNotFound)
	from /Users/mikhailkytyzov/bundle/ruby/2.6.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:35:in `each'
	from /Users/mikhailkytyzov/bundle/ruby/2.6.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:35:in `verify_installation!'
	from /Users/mikhailkytyzov/bundle/ruby/2.6.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:26:in `install!'
	from extconf.rb:7:in `<main>'

extconf failed, exit code 1

i tried to compile locally, but still the same error

@alex-tazy
Copy link

Have you tried this ?

@ignisf
Copy link
Collaborator

ignisf commented Oct 29, 2019

this will not work with mini racer which requires newer versions of v8

@mikekytyzov
Copy link
Author

@alex-tazy yes i did, nothing :<

@ignisf any workarounds maybe or something ? I will be very thankful

Thanks :)

@alex-tazy
Copy link

This works for me (macOS Catalina 10.15):

gem install libv8 -v '3.16.14.19' -- --with-system-v8
gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8@3.15

@f4z4on
Copy link

f4z4on commented Dec 23, 2019

If you don’t have system version of v8 (perhaps you have difficulty compiling it anyway or because you’re nervous relying on some package manager which has different version), you can do the following to fix the build:

env \
  CXX=clang++ \
  GYPFLAGS=-Dmac_deployment_target=10.9 \
gem install libv8 --version 3.16.14.19

This assumes you have typical developer setup on Mac – latest Xcode with command-line tools installed.

If you’re wondering how to translate this to bundle config, you can’t. Well, only partially because this gem’s build process recognizes CXX environment variable as well as --with-cxx command-line argument (see README).

It took me a lot of time to get to this. Default gyp config for this version of v8 sets deployment target to 10.5 which is no longer supported by the latest version of Xcode. If you raise it just to 10.6, it’ll start complaining about missing header files from standard library. If you include standard library using the hint on command-line, linker will complain it’s not supported for this deployment target. If you raise the deployment target to 10.9, everything will work. But then you can remove explicit stdlib.

Eventually, I tried setting deployment target to Catalina (10.15) – and it compiles. Could have saved some time, right? 😅

Possibly, there are other configuration combinations which might be more useful if someone wants to fix this in 3.16 branch while not breaking support for different compilers/OSes.

@davithss
Copy link

@frzng Thank you, it worked here! I spent several hours trying to fix this, and finally, I arrived here 😅 .

@yoonkwon
Copy link

yoonkwon commented Jan 2, 2020

This works for me (macOS Catalina 10.15):

gem install libv8 -v '3.16.14.19' -- --with-system-v8
gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8@3.15

if somebody gets error installing therubyracer, try brew install v8-315

@bsbodden
Copy link

bsbodden commented Jan 2, 2020

-Dmac_deployment_target=10.9

I can confirm this worked on Catalina with ruby 2.1.2p95 (legacy project). I added:

export CXX=clang++
export GYPFLAGS=-Dmac_deployment_target=10.15

to my .zshrc

@viktorianer
Copy link

This works for me (macOS Catalina 10.15):
gem install libv8 -v '3.16.14.19' -- --with-system-v8
gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8@3.15

if somebody gets error installing therubyracer, try brew install v8-315

brew install v8-315 worked on Catalina!

@mzagaja
Copy link

mzagaja commented Feb 12, 2020

This worked for me:

brew install v8 v8@3.15
bundle config build.libv8 --with-system-v8
bundle config build.therubyracer --with-v8-dir=/usr/local/opt/v8@3.15
bundle update libv8 therubyracer

@seanmakesgames
Copy link

seanmakesgames commented Mar 27, 2020

@ignisf Trying to upgrade mini_racer to latest on catalina.
Are we waiting for the v8 team to change their stuff so that we can compile on catalina, or is there something we can contribute in mini_racer or libv8 to get this working?

Edit: actually read the stuff above. Gonna try some stuff.
Edit-Edit: looks like something must be bunko on my coworkers machine because the binaries aren't coming down.

@mcarpent87
Copy link

If you don’t have system version of v8 (perhaps you have difficulty compiling it anyway or because you’re nervous relying on some package manager which has different version), you can do the following to fix the build:

env \
  CXX=clang++ \
  GYPFLAGS=-Dmac_deployment_target=10.9 \
gem install libv8 --version 3.16.14.19

This assumes you have typical developer setup on Mac – latest Xcode with command-line tools installed.

If you’re wondering how to translate this to bundle config, you can’t. Well, only partially because this gem’s build process recognizes CXX environment variable as well as --with-cxx command-line argument (see README).

It took me a lot of time to get to this. Default gyp config for this version of v8 sets deployment target to 10.5 which is no longer supported by the latest version of Xcode. If you raise it just to 10.6, it’ll start complaining about missing header files from standard library. If you include standard library using the hint on command-line, linker will complain it’s not supported for this deployment target. If you raise the deployment target to 10.9, everything will work. But then you can remove explicit stdlib.

Eventually, I tried setting deployment target to Catalina (10.15) – and it compiles. Could have saved some time, right? 😅

Possibly, there are other configuration combinations which might be more useful if someone wants to fix this in 3.16 branch while not breaking support for different compilers/OSes.

You are a freaking hero! Thank you!!

@benr75
Copy link

benr75 commented May 8, 2020

This is what finally worked for me on Catalina:

brew install v8@3.15
env CXX=clang++ GYPFLAGS=-Dmac_deployment_target=10.15
gem install libv8 --version 3.16.14.19
gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8@3.15

@b33rcity
Copy link

Nothing in this thread has worked for me so far. I've come across multiple threads in various Github repos and on StackOverflow all suggesting the same steps, and a subset of other participants reporting that these steps are not working. I think people are overlooking this line from the error when running gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8@3.15:

 By using --with-system-v8, you have chosen to use the version  (Libv8::Location::System::NotFoundError) of V8 found on your system and *not* the one that is bundled with the libv8 rubygem.

This sounds to me like the initial compilation of v8, or brew's setting of symlinks, or something, failed. Or, libv8's installer is accepting the string "(Libv8::Location::System::NotFoundError)" as a version or path and then reporting a successful installation when it did not actually succeed. Fwiw, it's at least partly working, as I get this as a result:

$ ls /Library/Ruby/Gems/2.6.0/gems/libv8-3.16.14.19/
CHANGELOG.md		ext			spec
Gemfile			lib			thefrontside.png
README.md		libv8.gemspec		vendor
Rakefile		patches
appveyor.yml		release

If I try removing the --with-system-v8 switch, I get this helpful suggestion:

clang: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead

My understanding from brew's post on the matter is that Catalina (and Mojave) don't have libstdc++ anymore. Unfortunately, it has no effect if I try adding the suggested flag: gem install libv8 -v '3.16.14.19' -- -stdlib=libc++ gives me the exact same error, so I guess there's no logic to pass this switch to clang. I'm not all that familiar with clang and quick googling couldn't confirm or deny if it's possible to set that with an environment variable.

It also made no difference if I set GYPFLAGS=-Dmac_deployment_target to 10.9 or 10.15, or if I tried using v8@8.1 instead of v8@3.15, or by passing the real path to the v8 directory rather than brew's symlink to therubyracer. Whatever permutation I try, therubyracer seems to think that my libv8 version is (Libv8::Location::System::NotFoundError).

@kleytonmr
Copy link

kleytonmr commented Jun 28, 2020

This worked for me:

brew install v8 v8@3.15
bundle config build.libv8 --with-system-v8
bundle config build.therubyracer --with-v8-dir=/usr/local/opt/v8@3.15
bundle update libv8 therubyracer

Thanks bro!!! <3 Worked on Catalina 10.15.5

@nightpool
Copy link
Collaborator

Hi all, we've published binary versions for Catalina for both the current 7.3 release and the upcoming 8.4 release. Users of therubyracer are encouraged to switch to mini_racer, which uses up to date versions of v8 that have been compiled for Catalina.

@jfanchime
Copy link

Nothing in this thread has worked for me so far. I've come across multiple threads in various Github repos and on StackOverflow all suggesting the same steps, and a subset of other participants reporting that these steps are not working. I think people are overlooking this line from the error when running gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8@3.15:

 By using --with-system-v8, you have chosen to use the version  (Libv8::Location::System::NotFoundError) of V8 found on your system and *not* the one that is bundled with the libv8 rubygem.

This sounds to me like the initial compilation of v8, or brew's setting of symlinks, or something, failed. Or, libv8's installer is accepting the string "(Libv8::Location::System::NotFoundError)" as a version or path and then reporting a successful installation when it did not actually succeed. Fwiw, it's at least partly working, as I get this as a result:

$ ls /Library/Ruby/Gems/2.6.0/gems/libv8-3.16.14.19/
CHANGELOG.md		ext			spec
Gemfile			lib			thefrontside.png
README.md		libv8.gemspec		vendor
Rakefile		patches
appveyor.yml		release

If I try removing the --with-system-v8 switch, I get this helpful suggestion:

clang: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead

My understanding from brew's post on the matter is that Catalina (and Mojave) don't have libstdc++ anymore. Unfortunately, it has no effect if I try adding the suggested flag: gem install libv8 -v '3.16.14.19' -- -stdlib=libc++ gives me the exact same error, so I guess there's no logic to pass this switch to clang. I'm not all that familiar with clang and quick googling couldn't confirm or deny if it's possible to set that with an environment variable.

It also made no difference if I set GYPFLAGS=-Dmac_deployment_target to 10.9 or 10.15, or if I tried using v8@8.1 instead of v8@3.15, or by passing the real path to the v8 directory rather than brew's symlink to therubyracer. Whatever permutation I try, therubyracer seems to think that my libv8 version is (Libv8::Location::System::NotFoundError).

I'm having the same issue, none of the solutions online works for me.

RSO pushed a commit to RSO/zxcvbn-ruby that referenced this issue Jan 4, 2021
I had trouble installing the development dependencies on my local machine and was pointed towards using `mini_racer` over `therubyracer` in this comment: rubyjs/libv8#282 (comment)

It seems like therubyracer was previously only used for the tests, so in order to verify that this works I ran `bundle exec rspec` and verified that all tests succeeded.
@wtfiwtz
Copy link

wtfiwtz commented Feb 14, 2021

If you are still struggling, particularly on Big Sur (11.2.1 for me) then have a look over here:

https://stackoverflow.com/questions/64956972/how-can-i-install-gem-libv8-in-mac-os-big-sur-11-0
#305

For prior to Big Sur: https://gist.github.com/fernandoaleman/868b64cd60ab2d51ab24e7bf384da1ca

For Apple Silicon M1 chips:
#309

Installing the gems libv8 and mini_racer worked ok using gem install based on the current releases but bundle install or bundle update would always fail as it needed to build libv8 from source.

I attempted to set up xcode-select -s /Applications/Xcode.app/Contents/Developer and brew install ninja to get the sources to build but I think it was installing the .gem manually and modifying the Gemfile.lock to force it to -x86_64-darwin-20 that worked in the end.

@nightpool
Copy link
Collaborator

@wtfiwtz This issue thread is about problems building on Catalina, which have been resolved. Issues building on Big Sur should be handled in a separate thread.

@speckworks
Copy link

This worked for me:

brew install v8 v8@3.15
bundle config build.libv8 --with-system-v8
bundle config build.therubyracer --with-v8-dir=/usr/local/opt/v8@3.15
bundle update libv8 therubyracer

Thank You so Much. Working on Catalina 10.15.6

@noslowerdna
Copy link

Thanks

@MattBudz
Copy link

MattBudz commented Feb 2, 2022

If you don’t have system version of v8 (perhaps you have difficulty compiling it anyway or because you’re nervous relying on some package manager which has different version), you can do the following to fix the build:

env \
  CXX=clang++ \
  GYPFLAGS=-Dmac_deployment_target=10.9 \
gem install libv8 --version 3.16.14.19

This assumes you have typical developer setup on Mac – latest Xcode with command-line tools installed.

If you’re wondering how to translate this to bundle config, you can’t. Well, only partially because this gem’s build process recognizes CXX environment variable as well as --with-cxx command-line argument (see README).

It took me a lot of time to get to this. Default gyp config for this version of v8 sets deployment target to 10.5 which is no longer supported by the latest version of Xcode. If you raise it just to 10.6, it’ll start complaining about missing header files from standard library. If you include standard library using the hint on command-line, linker will complain it’s not supported for this deployment target. If you raise the deployment target to 10.9, everything will work. But then you can remove explicit stdlib.

Eventually, I tried setting deployment target to Catalina (10.15) – and it compiles. Could have saved some time, right? 😅

Possibly, there are other configuration combinations which might be more useful if someone wants to fix this in 3.16 branch while not breaking support for different compilers/OSes.

I can confirm this works with Monteray 12.2 but bumping up the deployment target to 12.2

@viktorianer
Copy link

I just had this problem on an old project with Rails 5 again, where I use Docker with ruby:2.6.10-slim-buster image. And nothing from above helped.

I could install gem install libv8:3.16.14.19 and gem install therubyracer:0.12.3 without Bundler and without any options.

Until I realized, that in my Docker setup I like to use bundle config force_ruby_platform true (which works in new Rails 6 and 7 projects), resulting in not being able to install the gems via Bundler on Ruby 2.6.10 and Rails 5.2.8. After I removed the bundle config unset force_ruby_platform, I could install it with Bundler too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests