Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ language: php

php:
- 7.0
# - 7.1
- 7.1
- nightly

matrix:
Expand All @@ -17,8 +17,8 @@ env:
- NO_INTERACTION=1
- TEST_TIMEOUT=120
matrix:
- V8=5.4
- V8=5.4 TEST_PHP_ARGS=-m
- V8=5.7
- V8=5.7 TEST_PHP_ARGS=-m

before_install:
- sudo add-apt-repository ppa:pinepain/libv8-${V8} -y
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ project(php_v8)

# NOTE: This CMake file is just for syntax highlighting in CLion

include_directories(/usr/local/opt/v8@5.7/include)
include_directories(/usr/local/opt/v8@5.7/include/libplatform)

include_directories(/usr/local/include/php)
include_directories(/usr/local/include/php/TSRM)
include_directories(/usr/local/include/php/Zend)
Expand Down
90 changes: 23 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ in your IDE and other code-analysis tools.

## Installation

### Requirements

#### V8
You will need a recent v8 Google JavaScript engine version installed. At this time the extension is tested on 5.7.202.

#### PHP
This extension is PHP7-only. It works and tested with both PHP 7.0 and PHP 7.1.

#### OS
This extension works and tested on x64 Linux and macOS. As of written it is Ubuntu 16.04 LTS Xenial Xerus, amd64
and macOS 10.12.1. Windows is not supported at this time.

### Quick guide

#### Ubuntu
Expand All @@ -82,77 +94,25 @@ $ sudo apt-get install -y php7.0 php-v8
$ php --ri v8
```

While [pinepain/php](https://launchpad.net/~pinepain/+archive/ubuntu/php) PPA targets to contain all necessary
extensions with dependencies, you may find useful
[pinepain/libv8-5.7](https://launchpad.net/~pinepain/+archive/ubuntu/libv8-5.7) and
[pinepain/php-v8](https://launchpad.net/~pinepain/+archive/ubuntu/php-v8) standalone PPAs.


#### OS X (homebrew)

```
$ brew tap homebrew/dupes
$ brew tap homebrew/php
$ brew install php70
$ brew install https://raw.githubusercontent.com/pinepain/packaging/master/homebrew/v8.rb
$ brew install https://raw.githubusercontent.com/pinepain/packaging/master/homebrew/php70-v8.rb
$ brew tap pinepain/devtools
$ brew install php70
$ brew install v8@5.7
$ brew install php70-v8
$ php --ri v8
```

### Requirements

#### V8
You will need a recent v8 Google JavaScript engine version installed. At this time the extension is tested on 5.4.420.

- For Ubuntu there is the [pinepain/libv8-5.4](https://launchpad.net/~pinepain/+archive/ubuntu/libv8-5.4) PPA.
To install libv8:

```
$ sudo add-apt-repository -y ppa:pinepain/libv8-5.4
$ sudo apt-get update -y
$ sudo apt-get install -y libv8-5.4-dev
```
- For OS X there is the [v8.rb][v8.rb] homebrew formula.
To install libv8:

```
$ brew install https://raw.githubusercontent.com/pinepain/packaging/master/homebrew/v8.rb
```

#### PHP 7

- For Ubuntu there is the [ondrej/php](https://launchpad.net/~ondrej/+archive/ubuntu/php) PPA by [Ondřej Surý](https://deb.sury.org).

To install `php7.0`:

```
$ sudo add-apt-repository -y ppa:ondrej/php
$ sudo apt-get update -y
$ sudo apt-get install -y php7.0
```
- For OS X there is the [homebrew/homebrew-php](https://github.com/Homebrew/homebrew-php) tap with php70, php71 and a large
variety extensions for them.

To install `php70`:

```
$ brew tap homebrew/homebrew-php
$ brew install php70
```


### Installing php-v8 from packages

- For Ubuntu there is the [pinepain/php-v8](https://launchpad.net/~pinepain/+archive/ubuntu/php-v8) PPA.

To install `php-v8`:

```
$ sudo add-apt-repository -y ppa:pinepain/php-v8
$ sudo apt-get update -y
$ sudo apt-get install -y php-v8
```
- For OS X there are the [php70-v8.rb][php70-v8.rb] and [php71-v8.rb][php71-v8.rb] homebrew formulas.

To install `php70-v8` do:

```
$ brew install https://raw.githubusercontent.com/pinepain/packaging/master/homebrew/php70-v8.rb
```
For macOS php-v8 formulae and dependencies provided by [pinepain/devtools](https://github.com/pinepain/homebrew-devtools) tap.

### Building php-v8 from sources

Expand Down Expand Up @@ -186,7 +146,3 @@ Copyright (c) 2015-2016 Bogdan Padalko <pinepain@gmail.com>

[v8-hello-world]: https://chromium.googlesource.com/v8/v8/+/master/samples/hello-world.cc
[v8-intro]: https://developers.google.com/v8/intro
[v8.rb]: https://github.com/pinepain/packaging/blob/master/homebrew/v8.rb
[php70-v8.rb]: https://github.com/pinepain/packaging/blob/master/homebrew/php70-v8.rb
[php71-v8.rb]: https://github.com/pinepain/packaging/blob/master/homebrew/php71-v8.rb
[php-v8-stubs]: https://github.com/pinepain/php-v8-stubs
82 changes: 33 additions & 49 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ PHP_ARG_WITH(v8, for V8 Javascript Engine,
[ --with-v8 Include V8 JavaScript Engine])

if test "$PHP_V8" != "no"; then
V8_LIB_DIR=""
V8_INCLUDE_DIR=""

SEARCH_PATH="/usr/local /usr"
SEARCH_FOR="include/v8.h"

DESIRED_V8_VERSION=5.7

# Path where v8 from packages we recommend are installed, it's /opt/libv8-MAJOR.MINOR on Ubuntu
# and /usr/local/opt/v8@MAJOR.MINOR on macOS
PRIORITY_SEARCH_PATH="/opt/libv8-${DESIRED_V8_VERSION} /usr/local/opt/v8@${DESIRED_V8_VERSION}"
SEARCH_PATH="${PRIORITY_SEARCH_PATH} /usr/local /usr"

if test -r $PHP_V8/$SEARCH_FOR; then
case $host_os in
darwin* )
Expand All @@ -14,28 +24,31 @@ if test "$PHP_V8" != "no"; then
LDFLAGS="$LDFLAGS -Wl,--rpath=$PHP_V8/$PHP_LIBDIR"
;;
esac
V8_DIR=$PHP_V8
V8_LIB_DIR=$PHP_V8/$PHP_LIBDIR
V8_INCLUDE_DIR=$PHP_V8/include
else
AC_MSG_CHECKING([for V8 files in default path])
for i in $SEARCH_PATH ; do
if test -r $i/$SEARCH_FOR; then
V8_DIR=$i
AC_MSG_RESULT(found in $i)
V8_LIB_DIR=$i/$PHP_LIBDIR
V8_INCLUDE_DIR=$i/include
fi
done
fi

if test -z "$V8_DIR"; then
if test -z "$V8_LIB_DIR"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please reinstall the v8 distribution])
AC_MSG_ERROR([Please reinstall the v8 distribution or provide valid path to it])
fi

PHP_ADD_INCLUDE($V8_DIR/include)
PHP_ADD_LIBRARY_WITH_PATH(v8, $V8_DIR/$PHP_LIBDIR, V8_SHARED_LIBADD)
AC_DEFINE_UNQUOTED([PHP_V8_LIB_DIR], ["$V8_LIB_DIR/"], [Root directory with libraries (and icu data file)])

PHP_ADD_INCLUDE($V8_INCLUDE_DIR)
PHP_ADD_LIBRARY_WITH_PATH(v8, $V8_LIB_DIR, V8_SHARED_LIBADD)
PHP_SUBST(V8_SHARED_LIBADD)
PHP_REQUIRE_CXX()


AC_CACHE_CHECK(for C standard version, ac_cv_v8_cstd, [
ac_cv_v8_cstd="c++11"
old_CPPFLAGS=$CPPFLAGS
Expand All @@ -54,54 +67,22 @@ if test "$PHP_V8" != "no"; then
case $host_os in
darwin* )
# MacOS does not support --rpath
LDFLAGS="-L$V8_DIR/$PHP_LIBDIR"
LDFLAGS="-L$V8_LIB_DIR"
;;
* )
LDFLAGS="-Wl,--rpath=$V8_DIR/$PHP_LIBDIR -L$V8_DIR/$PHP_LIBDIR"
LDFLAGS="-Wl,--rpath=$V8_LIB_DIR -L$V8_LIB_DIR"
;;
esac

PHP_ADD_INCLUDE($V8_DIR)

case $host_os in
darwin* )
static_link_extra="libv8_libplatform.a libv8_libbase.a"
#static_link_extra="libv8_base.a libv8_libbase.a libv8_libplatform.a libv8_snapshot.a"
;;
* )
static_link_extra="libv8_libplatform.a"
#static_link_extra="libv8_base.a libv8_libbase.a libv8_libplatform.a libv8_snapshot.a"
;;
esac

for static_link_extra_file in $static_link_extra; do
AC_MSG_CHECKING([for $static_link_extra_file])
static_link_dir=""

for i in $PHP_V8 $SEARCH_PATH ; do
if test -r $i/lib64/$static_link_extra_file; then
static_link_dir=$i/lib64
AC_MSG_RESULT(found in $i)
fi
if test -r $i/lib/$static_link_extra_file; then
static_link_dir=$i/lib
AC_MSG_RESULT(found in $i)
fi
done

if test -z "$static_link_dir"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please provide $static_link_extra_file next to the libv8.so])
fi

LDFLAGS="$LDFLAGS $static_link_dir/$static_link_extra_file"
done

LIBS=-lv8
CPPFLAGS="-I$V8_DIR/include -std=$ac_cv_v8_cstd"
LDFLAGS="$LDFLAGS -lv8_libbase -lv8_libplatform"
LIBS="-lv8 -lv8_libbase -lv8_libplatform"
CPPFLAGS="-I$V8_INCLUDE_DIR -std=$ac_cv_v8_cstd"
AC_LANG_SAVE
AC_LANG_CPLUSPLUS


# NOTE: it is possible to get version string from headers with simple regexp match
AC_CACHE_CHECK(for V8 version, ac_cv_v8_version, [
AC_TRY_RUN([
Expand All @@ -124,7 +105,7 @@ if test "$PHP_V8" != "no"; then
], [ac_cv_v8_version=`cat ./conftestval|awk '{print $1}'`], [ac_cv_v8_version=NONE], [ac_cv_v8_version=NONE])
])

V8_MIN_API_VERSION_STR=5.4.420
V8_MIN_API_VERSION_STR=5.7.202

if test "$ac_cv_v8_version" != "NONE"; then
ac_IFS=$IFS
Expand All @@ -147,15 +128,18 @@ if test "$PHP_V8" != "no"; then

# On OS X clang reports warnings in zeng_strings.h, like
# php/Zend/zend_string.h:326:2: warning: 'register' storage class specifier is deprecated [-Wdeprecated-register]
# We want to make building log cleaner, so let's suppress this warning
# also
# php/Zend/zend_operators.h:128:18: warning: 'finite' is deprecated: first deprecated in macOS 10.9 [-Wdeprecated-declarations]
# but as we want to track also deprecated methods from v8 we won't ignore -Wdeprecated-declarations warnings
# We want to make building log cleaner, so let's suppress only -Wdeprecated-register warning
ac_cv_suppress_register_warnings_flag="-Wno-deprecated-register"
#ac_cv_suppress_register_warnings_flag="-Wno-deprecated-register -Wno-deprecated-declarations"

AC_DEFINE([V8_DEPRECATION_WARNINGS], [1], [Enable compiler warnings when using V8_DEPRECATED apis.])
AC_DEFINE([V8_IMMINENT_DEPRECATION_WARNINGS], [1], [Enable compiler warnings to make it easier to see what v8 apis will be deprecated (V8_DEPRECATED) soon.])

AC_LANG_RESTORE
LIBS=$old_LIBS
#LDFLAGS=$old_LDFLAGS # we have to links some static libraries
#LDFLAGS=$old_LDFLAGS # we have to links some libraries
CPPFLAGS=$old_CPPFLAGS

if test -z "$TRAVIS" ; then
Expand Down
12 changes: 3 additions & 9 deletions php_v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ extern "C" {
extern zend_module_entry php_v8_module_entry;
#define phpext_v8_ptr &php_v8_module_entry

#ifndef PHP_V8_LIB_DIR
#define PHP_V8_LIB_DIR NULL
#endif

#ifndef PHP_V8_VERSION
#define PHP_V8_VERSION "0.2.0-dev"
Expand Down Expand Up @@ -70,12 +73,3 @@ ZEND_TSRMLS_CACHE_EXTERN();
ZEND_EXTERN_MODULE_GLOBALS(v8);

#endif //PHP_V8_H

/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
1 change: 1 addition & 0 deletions scripts/test_v8/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
hello_world
hello_world.dSYM
12 changes: 9 additions & 3 deletions scripts/test_v8/hello_world_build_deb.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/bin/bash

ROOT=/opt/libv8-5.7
LIB_DIR=$ROOT/lib/

SRC_DIR=$ROOT
INCLUDE_DIR=$ROOT/include

g++ hello_world.cpp -o hello_world \
-g \
-O2 \
-std=c++11 \
-I/usr/ \
-I/usr/include \
-L/usr/lib/ \
-I$SRC_DIR \
-I$INCLUDE_DIR \
-L$LIB_DIR \
-lv8_libbase \
-lv8_libplatform \
-lv8 \
Expand Down
14 changes: 11 additions & 3 deletions scripts/test_v8/hello_world_build_osx.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#!/bin/bash

ROOT=/usr/local/opt/v8@5.7
LIB_DIR=$ROOT/lib/

SRC_DIR=$ROOT
INCLUDE_DIR=$ROOT/include

g++ hello_world.cpp -o hello_world \
-g \
-O2 \
-std=c++11 \
-I/usr/local \
-I/usr/local/include \
-L/usr/local/lib/ \
-I$SRC_DIR \
-I$INCLUDE_DIR \
-L$LIB_DIR \
-lv8_libbase \
-lv8_libplatform \
-lv8 \
-lpthread

install_name_tool -add_rpath $LIB_DIR hello_world
14 changes: 2 additions & 12 deletions src/php_v8_a.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ void php_v8_init()
return;
}

v8::V8::InitializeICUDefaultLocation(PHP_V8_LIB_DIR);

// NOTE: if we use snapshot and extenal startup data then we have to initialize it (see https://codereview.chromium.org/315033002/)
// v8::V8::InitializeExternalStartupData(NULL);
v8::Platform *platform = v8::platform::CreateDefaultPlatform();
Expand All @@ -54,15 +56,3 @@ void php_v8_init()
// v8::V8::Dispose();
// v8::V8::ShutdownPlatform();
}




/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
Loading