The reason of this work is that I'm currently working on a web project which require latest web technology. One of these technologies is PHP/v8js.
sudo apt install build-essential chrpath re2c clang-dev git git-doc- Git (should be already installed)
- systemd-zram
- Google depot_tools
- A lot of coffeine and patience !!
- http://www.mccarroll.net/blog/v8_pi2/
- https://github.com/v8/v8/wiki/Building%20from%20Source
- https://github.com/phpv8/v8js/blob/php7/README.Linux.md
- https://github.com/v8/v8/wiki/Building%20with%20Gyp
- https://secure.php.net/manual/en/v8js.examples.php
zramctl && echo -e "\nCompression stats:" && zramstat && echo -e "\nMemory usage:" && free -mlhtIf you have less than 1Gb as total memory, you should increase it by modifying the file
/etc/systemd/zram.confand set thefactorvalue to50for example then restart themkzramservice.Depending on your embedded memory size, you may have around of 1.4Gb after that.
To restart the
mkzramservice, just execute this command:sudo systemctl restart mkzramThanks to the
zRamkernel module which is included in the Raspberry Pi kernel and my small project systemd-zram
export PATH=`pwd`/depot_tools:$PATH
ninjamay also be needed, in this case, have a look here and thereTo compile it, simply do:
./configure.py --bootstrapThen add it to the
path:
export PATH=`pwd`/ninja:$PATHgclient
fetch v8
cd v8You must have installed
gitanddepot_toolsfirst.This process will be long with almost no output so be patient
git checkout 4.9.385.28 // for examplegclient syncMake sure to remove host from compilation toolsets in the file v8/testing/gtest.gyp
Use Ctrl+\ then search for "'host', " (without '"') and replace (leave empty)
Then Ctrl+X and confirm to save the file
# Build (with internal snapshots)
export GYPFLAGS="-Dv8_use_external_startup_data=0"
# Force gyp to use system-wide ld.gold
export GYPFLAGS="${GYPFLAGS} -Dlinux_use_bundled_gold=0"
# Compile V8 (compilation succeed with -j1 | 1.4 Gb RAM / Failed with -j[2-4])
make native hardfp=on vf3p=off library=shared snapshot=on werror=no -j1
# Install to /opt/v8
sudo mkdir -pv /opt/v8/{lib,include}
sudo cp -v out/native/lib.target/lib*.so /opt/v8/lib/
sudo cp -Rv include/* /opt/v8/include
# Fix libv8.so's RUNPATH header
sudo chrpath -r '$ORIGIN' /opt/v8/lib/libv8.soNow, if compilation succeed without any issues, you must finger cross for the next step...
To verify if v8 is compiled properly, you should execute the unittests and hello-world scripts
# Go to the output directory
cd path-to-v8/out/native
# Run unit tests
./unittests
# If unit tests are passed, then say hello to the world :stuck_out_tongue_winking_eye:
./hello-world
# You should see as result :
Hello, World!git clone https://github.com/phpv8/v8js.git
cd v8js
phpize
./configure --with-v8js=/opt/v8
make -j $(nproc)
make testIf during the
make testprocess, you see that all tests are failing, it means that yourv8jscode won't run π
If all tests are passed successfully, you may go to the next step and install the library then update your PHP config files
sudo make install
# Now updating the PHP / Apache2 config file
sudo nano /etc/php/7.0/apache2/php.ini
# Add these lines at the end
[v8js]
extension=v8js.so
# Repeat the process for the PHP / CLI config file
sudo nano /etc/php/7.0/cli/php.ini
# To finish, restart your webserver (Apache 2 in my case)
sudo systemctl restart apache2
# Verify the status
sudo systemctl status apache2Go ahead on PHP v8js examples and see if that runs as shown.
If the above example is working, you should see in your browser :
Hello World! int(13)Otherwise, you may get something like that in your logs :
==== C stack trace ===============================
#
# Fatal error in ../src/snapshot/natives-external.cc, line 122
# Check failed: holder_.
#
==== C stack trace ===============================
#
# Fatal error in ../src/snapshot/natives-external.cc, line 122
# Check failed: holder_.
#
[Tue Jan 10 23:49:17.151018 2017] [core:notice] [pid 26162] AH00051: child pid 26169 exit signal Illegal instruction (4), possible coredump in /etc/apache2
[Tue Jan 10 23:49:17.151691 2017] [core:notice] [pid 26162] AH00051: child pid 26175 exit signal Illegal instruction (4), possible coredump in /etc/apache2
==== C stack trace ===============================
#
# Fatal error in ../src/snapshot/natives-external.cc, line 122
# Check failed: holder_.
#
[Tue Jan 10 23:49:19.161500 2017] [core:notice] [pid 26162] AH00051: child pid 26171 exit signal Illegal instruction (4), possible coredump in /etc/apache2
==== C stack trace ===============================
#
# Fatal error in ../src/snapshot/natives-external.cc, line 122
# Check failed: holder_.
#
[Tue Jan 10 23:49:24.167417 2017] [core:notice] [pid 26162] AH00051: child pid 26177 exit signal Illegal instruction (4), possible coredump in /etc/apache2
==== C stack trace ===============================
#
# Fatal error in ../src/snapshot/natives-external.cc, line 122
# Check failed: holder_.
#
[Tue Jan 10 23:49:55.203367 2017] [core:notice] [pid 26162] AH00051: child pid 26179 exit signal Illegal instruction (4), possible coredump in /etc/apache2
==== C stack trace ===============================
#
# Fatal error in ../src/snapshot/natives-external.cc, line 122
# Check failed: holder_.
#No need to say that the compilation has failed somewhere...
I'm still trying actually to make this process succeed... but there is still some fight right now !And the winner... Me π The compilation took all night long to be done but now it works !