phpv8 / v8js

V8 Javascript Engine for PHP — This PHP extension embeds the Google V8 Javascript Engine
http://pecl.php.net/package/v8js
MIT License
1.83k stars 200 forks source link

Compiling on Win32, crash #162

Closed maryo closed 9 years ago

maryo commented 9 years ago

Hi. I compiled the extension on Win32 using VC12 (Visual Studio 2013) using the guide https://github.com/preillyme/v8js/blob/master/README.Win32.md

  1. I fetched v8 (4.7.10 version) and it's dependencies using depot tools (fetch v8) rather than manually
  2. compiled it using VS 2013, everything looks OK, the compiled unittest.exe outputs
[==========] 1994 tests from 107 test cases ran. (2595 ms total)
[  PASSED  ] 1994 tests.
  1. copied the libs and headers to deps in PHP build tree
  2. copied v8js from this repo (using https://github.com/preillyme/v8js/archive/0.2.3.zip) to ext folder in PHP build tree
  3. modified config.win32 so it matches the version (there is an ancient version defined there)
AC_DEFINE("PHP_V8_API_VERSION", "4007010", "", false);
AC_DEFINE("PHP_V8_VERSION", "4.7.10", "", true);
  1. configure --disable-all --enable-cli --with-v8js

Everything compiled well, even the v8 extension appears in output of phpinfo()

v8js
V8 Javascript Engine    enabled
V8 Engine Compiled Version  4.7.10
V8 Engine Linked Version    4.7.0 (candidate)
Version 0.2.3

But when i wanted to test whether it works, just instantiating the V8Js class using new V8Js(); crashes PHP.

I was wondereing whether it couldn't be related to https://github.com/preillyme/v8js/commit/e07ea80805af40c71b5513461020c6081ee49e63#diff-6a1f09ef46156d3e46f5ab1b244564d9

But actually i don't know. Is this option or an equivalent available on Windows at all? Could someone help?

Or could it be a v8 version problem? What was the last v8 version successfully compiled which works with v8js extension?

I managed to compile PHP 5.6.12 x86 and all it's extensions (static and shared) which are present in windows build at http://windows.php.net/download/ using VC12 + v8js. I'd share it somewhere. Looks like everything works, just the v8js :)

BTW Is this extension compatible with PHP7? I'd like to compile it for PHP7 too if it's compatible.

stesie commented 9 years ago

Hi, I agree that that very likely is the case. Have you tried also passing -Dv8_use_snapshot='false' to the gyp_v8 call? (maybe see official docs at https://code.google.com/p/v8-wiki/wiki/BuildingWithGYP)

Please let me know if that works then. I haven't tried building V8Js for Windows for a while (I actually don't have a build environment at hand, I used to rent a EC2 instance on AWS but gave tat up a while ago)

Regarding PHP7, V8Js isn't really compatible so far. I've started a php7 branch in my v8js fork (so Github is not currently in sync with my latest work), so far it compiles fine at passes about 75% of the test suite. So still some work left to be done :-) But I think it definitely will be available within two weeks or so.

maryo commented 9 years ago

Thanks a lot, it helped. I have tried it and specifying the -Dv8_use_snapshot option alone didn't help, it stopped producing the v8.lib and v8.dll files. Then I've noticed -Dcomponent option at the official docs (not under Windows section). It was apparently building a static library.

So gyp_v8 -Dcomponent=shared_library -Dv8_use_snapshot=0 did the trick and it works properly now. Iit's just needed to build only the v8 project from the all.sln VS solution, some of the rest fails when the -Dcomponent=shared_library option is specified.

ad PHP7: Good news :+1:

EDIT: the -Dcomponent=shared_library option is already mentioned in README.Win32.md. I missed it, but the -Dv8_use_snapshot=0 is also needed ofc.

stesie commented 9 years ago

@maryo still using V8Js and interested in sharing your build artifacts? Would be super cool if you could; I have a Linux box around (where the Jenkins hosting is hosted actually) where I could provide the files if traffic is a problem.

I'm wondering how to get a CI test environment for Windows back in place; maybe you want to join the Gitter chat for further negotiations

maryo commented 9 years ago

I didn't get to use it yet but I want to try to play with GraphQL in PHP using original JS implementation from FB .

I've uploaded PHP containing all standard extensions (which was needed to be compiled using VC12 because of the v8) to my GH here: https://github.com/maryo/php-5.6.13-win32-VC12

v8js 0.2.6 extension + few other additional ones https://github.com/maryo/php-5.6-extensions-win32-VC12 The extensions are mostly compiled using deps from http://windows.php.net/downloads/php-sdk/deps/vc11/. Looks like the .lib files are compatible even it's compiled using VC11.

But I'm not sure what to do with the CI.

Not sure if it could work here https://pecl.php.net/package/v8js since they use VC11 for PHP 5.6. Maybe. But PHP7 is compiled using VC14 (2015) so it could work there in the future.