phpv8 / v8js

V8 Javascript Engine for PHP — This PHP extension embeds the Google V8 Javascript Engine

Home Page:http://pecl.php.net/package/v8js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't install v8js on macOS Catalina

Jiri-Mihal opened this issue · comments

I can't install V8Js on macOS Catalina, PHP 7.4.13. I tried two ways of installation:

  1. First Way: Install the latest version of V8 with brew and then compile v8js.
  2. Second Way: Compile the older version of v8 from the source and then compile v8js.

Both ways without success. Any ideas?

First Way Steps

Installation of the latest version of v8 with Brew:

brew install php
php -v
PHP 7.4.13 (cli) (built: Nov 26 2020 04:59:36) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.13, Copyright (c), by Zend Technologies
brew install v8
🍺  /usr/local/Cellar/v8/8.7.220.25: 74 files, 40.4MB

Compilation of v8js:

cd ~
git clone https://github.com/phpv8/v8js.git
cd v8js
phpize
./configure CXXFLAGS="-Wno-c++11-narrowing" --with-v8js="/usr/local/Cellar/v8/8.7.220.25/libexec" --with-php-config="/usr/local/Cellar/php/7.4.13/bin/php-config"

Here I get this error:

checking for libv8_libplatform... found
checking for V8 version... NONE
configure: error: could not determine libv8 version

I also tried to copy v8 files to default path with: cp -r /usr/local/Cellar/v8/8.7.220.25/libexec/include/* /usr/local/include, cp /usr/local/Cellar/v8/8.7.220.25/libexec/lib*.dylib /usr/local/lib/. Then I tried some different configurations: ./configure CXXFLAGS="-Wno-c++11-narrowing", ./configure CXXFLAGS="-Wno-c++11-narrowing" LDFLAGS="-lstdc++", and ./configure --with-v8js=/opt/v8 LDFLAGS="-lstdc++" CPPFLAGS="-DV8_COMPRESS_POINTERS". No luck:/

Second Way Steps

Compiling older version v8:

mkdir ~/tmp & cd ~/tmp
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=`pwd`/depot_tools:"$PATH"
fetch v8
cd v8
git checkout 7.4.288.25
gclient sync
nano build/mac/find_sdk.py

Here I update regex to accept newer version of SDK. macOS Catalina comes with version 11. ^MacOSX(\10\.\d+)\.sdk$ to ^MacOSX(\d+\.\d+)\.sdk$.

tools/dev/v8gen.py -vv x64.release -- is_component_build=true use_custom_libcxx=false
ninja -C out.gn/x64.release
cp -r include/* /usr/local/include
cp lib*.dylib /usr/local/lib/

Compilation of v8js:

cd ~/tmp
git clone https://github.com/phpv8/v8js.git
cd v8js
phpize
./configure CXXFLAGS="-Wno-c++11-narrowing" LDFLAGS="-lstdc++"
make

Here I get bunch of warnings.

/Users/jirimihal/tmp/v8js/v8js_array_access.cc:213:25: warning: 'GetEnteredContext' is deprecated: Use
      GetEnteredOrMicrotaskContext(). [-Wdeprecated-declarations]
                        result->Set(isolate->GetEnteredContext(), i ++, V8JS_INT(j));
                                             ^
/usr/local/include/v8.h:7921:3: note: 'GetEnteredContext' has been explicitly marked deprecated here
  V8_DEPRECATED("Use GetEnteredOrMicrotaskContext().",
  ^
/usr/local/include/v8config.h:307:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
/Users/jirimihal/tmp/v8js/v8js_array_access.cc:213:4: warning: ignoring return value of function
      declared with 'warn_unused_result' attribute [-Wunused-result]
                        result->Set(isolate->GetEnteredContext(), i ++, V8JS_INT(j));
...and so on...
4 warnings generated.
warning: no debug symbols in executable (-arch x86_64)
----------------------------------------------------------------------
Libraries have been installed in:
   /Users/jirimihal/tmp/v8js/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
     during execution

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.
make test

Almost all tests fail.

=====================================================================
PHP         : /usr/local/Cellar/php/7.4.13/bin/php 
PHP_SAPI    : cli
PHP_VERSION : 7.4.13
ZEND_VERSION: 3.4.0
PHP_OS      : Darwin - Darwin Jiris-MacBook-Pro.local 19.6.0 Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64 x86_64
INI actual  : /Users/jirimihal/tmp/v8js/tmp-php.ini
More .INIs  :   
---------------------------------------------------------------------
PHP         : /usr/local/Cellar/php/7.4.13/bin/phpdbg 
PHP_SAPI    : phpdbg
PHP_VERSION : 7.4.13
ZEND_VERSION: 3.4.0
PHP_OS      : Darwin - Darwin Jiris-MacBook-Pro.local 19.6.0 Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64 x86_64
INI actual  : /Users/jirimihal/tmp/v8js/tmp-php.ini
More .INIs  : 
---------------------------------------------------------------------
CWD         : /Users/jirimihal/tmp/v8js
Extra dirs  : 
VALGRIND    : Not used
=====================================================================
TIME START 2020-11-27 17:22:33
=====================================================================
FAIL Test V8::executeString() : Check ArrayAccess interface wrapping [tests/array_access.phpt] 
FAIL Test V8::executeString() : Check ArrayAccess live binding [tests/array_access_001.phpt] 
FAIL Test V8::executeString() : Use ArrayAccess with JavaScript native push method [tests/array_access_002.phpt] 
FAIL Test V8::executeString() : Export PHP methods on ArrayAccess objects [tests/array_access_003.phpt] 
FAIL Test V8::executeString() : Export PHP properties on ArrayAccess objects [tests/array_access_004.phpt] 
...and so on...
=====================================================================
TIME END 2020-11-27 17:22:52

=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped    :    0
Exts tested     :   65
---------------------------------------------------------------------

Number of tests :  177               175
Tests skipped   :    2 (  1.1%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :  172 ( 97.2%) ( 98.3%)
Tests passed    :    3 (  1.7%) (  1.7%)
---------------------------------------------------------------------
Time taken      :   19 seconds
=====================================================================

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Test V8::executeString() : Check ArrayAccess interface wrapping [tests/array_access.phpt]
Test V8::executeString() : Check ArrayAccess live binding [tests/array_access_001.phpt]
Test V8::executeString() : Use ArrayAccess with JavaScript native push method [tests/array_access_002.phpt]
Test V8::executeString() : Export PHP methods on ArrayAccess objects [tests/array_access_003.phpt]
Test V8::executeString() : Export PHP properties on ArrayAccess objects [tests/array_access_004.phpt]
...and so on...
=====================================================================

You may have found a problem in PHP.
This report can be automatically sent to the PHP QA team at
http://qa.php.net/reports and http://news.php.net/php.qa.reports
This gives us a better understanding of PHP's behavior.
If you don't want to send the report immediately you can choose
option "s" to save it.	You can then email it to qa-reports@lists.php.net later.
Do you want to send this report now? [Yns]: n
make: *** [test] Error 1

I haven't gotten all the tests to pass either for php@7.4 in general, but I got it working? See below.

[Catalina 10.15.7, PHP 7.4.13, Macbook Pro 16", 2019]

  1. Latest v8 from homebrew is v8.7 so we can't use it. Save this latest v8.6 formula locally as v8.rb: https://raw.githubusercontent.com/Homebrew/homebrew-core/0a6171330678879285f2c566db9349da421d6f62/Formula/v8.rb
  2. brew install v8.rb
  3. Make required matching phpv8js build folder structure
mkdir -p /usr/local/Cellar/v8/8.6.395.23/libexec/lib
cp /usr/local/Cellar/v8/8.6.395.23/libexec/* /usr/local/Cellar/v8/8.6.395.23/libexec/lib
  1. Clone and configure: (configure instruction I found in linux build file)
git clone https://github.com/phpv8/v8js
cd v8js
./configure --with-v8js="/usr/local/Cellar/v8/8.6.395.23/libexec" LDFLAGS="-lstdc++" CPPFLAGS="-DV8_COMPRESS_POINTERS"

Note: You can't use CPPFLAGS="-DV8_COMPRESS_POINTERS" unless your v8 is v8+, so what @Jiri-Mihal has above might work for v7.4.288.25 if you remove this argument.

  1. Manually apply this patch on line 132 see: 94db71e - otherwise, you get 1 failed test. Thanks @nvq247

Or you can run this command in the v8js folder: sed -i -e '132s/retval/object/g' v8js_v8object_class.cc

  1. Build and test
make
make test

Result: 2 tests skipped. Maybe due to some php@7.4 version conditional instruction to skip but we can basically say that all tests passed?

=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped    :    0
Exts tested     :   65
---------------------------------------------------------------------

Number of tests :  177               175
Tests skipped   :    2 (  1.1%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :    0 (  0.0%) (  0.0%)
Tests passed    :  175 ( 98.9%) (100.0%)
---------------------------------------------------------------------
Time taken      :   19 seconds
=====================================================================

  1. Install it
make install
  1. Link the extension="v8js.so" file to php --info ini folder, brew restart php... You know the rest. Enjoy.

How to install v8js with PHP v7.4.13 on macOS Catalina

Thank you @noogen, you helped me a lot!👍 In your example v8.rb link leads to version 7.4.288.25 and also phpize is missing before ./configure, so I made a corrected step-by-step guide for all others:

  1. Download older formula of v8 (ver 8.6.395.23):
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/138b52806dad359b9f2c8da1de451b787a763944/Formula/v8.rb
  1. Install v8 from the downloaded formula:
brew install v8.rb

If brew can't install v8 from the downloaded v8.rb file, you can try to build version 8.6.395.23 of v8 by yourself, see the guide "Compiling older version v8" above in this thread.

  1. Make required matching phpv8js build folder structure:
mkdir -p /usr/local/Cellar/v8/8.6.395.23/libexec/lib
cp /usr/local/Cellar/v8/8.6.395.23/libexec/* /usr/local/Cellar/v8/8.6.395.23/libexec/lib
  1. Download phpv8js:
git clone https://github.com/phpv8/v8js
cd v8js
  1. Build phpv8js:
phpize

The following command patches file v8js_v8object_class.cc, otherwise you get 1 failed test. See 94db71e - Thanks @nvq247

sed -i -e '132s/retval/object/g' v8js_v8object_class.cc
./configure --with-v8js="/usr/local/Cellar/v8/8.6.395.23/libexec" LDFLAGS="-lstdc++" CPPFLAGS="-DV8_COMPRESS_POINTERS"
make
make test
make install
  1. Add line extension="v8js.so" to beginning of php.in file:
php --ini
nano _{path to php.ini}_
brew services restart php