Search code examples
phpv8

Compiling v8js extension after V8 was built with gn build (as opposed to gyp)


Google has decided to deprecate gyp builds of V8. The recommended method is to build with gn.

However, PHP extension v8js fails to find required libraries and exits with:

checking for V8 Javascript Engine... yes, shared
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking for C standard version... c++11
checking how to allow c++11 narrowing... -Wno-narrowing
checking for V8 version... NONE
configure: error: could not determine libv8 version

What needs to be done to compile PHP v8js extension after V8 is compiled with gn?

Thanks!


Solution

  • After two days of experimentation I've successfully compiled v8js against V8 that was built with gn (as opposed to now-deprecated gyp).

    Follow initial checkout instructions https://github.com/v8/v8/wiki/Building%20with%20GN.

    After tools/dev/v8gen.py x64.release step do this:

    $ nano out.gn/x64.release/args.gn
    

    It should looks like this:

    is_debug = false
    target_cpu = "x64"
    is_component_build = true
    v8_enable_i18n_support = false
    

    At this point I could not figure out how to correctly build i18n support.

    Not sure if this is really required, but I also updated out.gn/x64.release/v8_build_config.json with: "v8_enable_i18n_support": false.

    Compile (takes about 45 minutes):

    $ ninja -C out.gn/x64.release
    

    Once compiled:

    $ cp out.gn/x64.release/lib*.so /usr/lib/ && cp -R include/* /usr/include
    $ cp out.gn/x64.release/natives_blob.bin /usr/lib
    $ cp out.gn/x64.release/snapshot_blob.bin /usr/lib
    $ cd out.gn/x64.release/obj
    $ ar rcsDT libv8_libplatform.a v8_libplatform/*.o
    $ echo -e "create /usr/lib/libv8_libplatform.a\naddlib /usr/local/src/v8/out.gn/x64.release/obj/libv8_libplatform.a\nsave\nend" | sudo ar -M
    

    After that check out v8js and compile as usual:

    phpize
    ./configure
    make && make install