DEV Community

Cover image for How to build plv8 2.3.0 for Raspberry Pi 3
Junichi Kajiwara
Junichi Kajiwara

Posted on

How to build plv8 2.3.0 for Raspberry Pi 3

What is plv8

see:

Building V8

I have done this by cross compiling.

You have to do following steps on Linux box(x86_64).

Installing depot_tools

cd ~ mkdir -p local/src cd local mkdir build cd build git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git export PATH=$PATH:~/local/depot_tools 
Enter fullscreen mode Exit fullscreen mode

fetching v8 source

cd src fetch v8 cd v8 git checkout 6.4.388.40 
Enter fullscreen mode Exit fullscreen mode

6.4.388.40 : plv8-2.3.0 uses this version.

You may add follwing line to ../.gclient .

target_os = ['unix'] 
Enter fullscreen mode Exit fullscreen mode

then, you call gclient sync.

gclient sync 
Enter fullscreen mode Exit fullscreen mode

Cross compileing for Raspberry Pi

tools/dev/v8gen.py arm.release -- \ is_component_build=false v8_static_library=true v8_use_snapshot=true \  v8_use_external_startup_data=false v8_enable_i18n_support=false 
Enter fullscreen mode Exit fullscreen mode
gn args out.gn/arm.release 
Enter fullscreen mode Exit fullscreen mode

then,edit parameters following:

is_debug = false target_cpu = "arm" v8_target_cpu = "arm" # Additional command-line args: is_component_build=false v8_static_library=true v8_use_snapshot=true v8_use_external_startup_data=false v8_enable_i18n_support=false 
Enter fullscreen mode Exit fullscreen mode

building d8 and libv8*.a

ninja -C out.gn/arm.release d8 
Enter fullscreen mode Exit fullscreen mode

When your build success,you'll have these files.

ls out.gn/arm.release/libv8*.a libv8_base.a libv8_libbase.a libv8_libplatform.a libv8_libsampler.a libv8_snapshot.a 
Enter fullscreen mode Exit fullscreen mode

Copying files to raspberry pi

ssh pi@raspberrry.local mkdir $HOME/local/v8 scp out.gn/arm.release/libv8*.a pi@raspberrypi.local:/home/pi/local/v8 scp include pi@raspberrypi.local:/home/pi/local/v8 
Enter fullscreen mode Exit fullscreen mode

after this step,you may work on your raspberry pi.

Installing libc++

before build plv8,you'll need libc++.

sudo apt install libc++-dev libunwind-dev 
Enter fullscreen mode Exit fullscreen mode

Installing PostgreSQL

Of course you'll need PostgreSQL.Because plv8 is an extension of the PostgreSQL.

sudo apt install postgresql-server-dev-9.6 postgresql-9.6 
Enter fullscreen mode Exit fullscreen mode

Building plv8 itself on Raspberry Pi

mkdir -p ~/local/src cd ~/local/src curl https://github.com/plv8/plv8/archive/v2.3.0.zip unzip v2.3.0.zip cd plv8-2.3.0 
Enter fullscreen mode Exit fullscreen mode

copy v8 headers and libraries to plv8's source tree

mkdir -p build/v8/out.gn/x64.release/obj cp -r ~/local/v8/include build/v8 cp ~/local/v8/lib*a build/v8/out.gn/x64.release/obj 
Enter fullscreen mode Exit fullscreen mode

Edit Makefile

Now, you have built v8 libraries.you don't need build v8 again.
So, you can edit Makefile following:

AUTOV8_DIR = build/v8 AUTOV8_OUT = build/v8/out.gn/x64.release/obj - AUTOV8_DEPOT_TOOLS = build/depot_tools AUTOV8_LIB = $(AUTOV8_OUT)/libv8_snapshot.a AUTOV8_STATIC_LIBS = -lv8_base -lv8_snapshot -lv8_libplatform -lv8_libbase -lv8_libsampler - export PATH := $(abspath $(AUTOV8_DEPOT_TOOLS)):$(PATH)  SHLIB_LINK += -L$(AUTOV8_OUT) -L$(AUTOV8_OUT)/third_party/icu $(AUTOV8_STATIC_LIBS) -- V8_OPTIONS = is_component_build=false v8_static_library=true v8_use_snapshot=true v8_use_external_startup_data=false  - ifndef USE_ICU - V8_OPTIONS += v8_enable_i18n_support=false - endif  - all: v8 # For some reason, this solves parallel make dependency. - plv8_config.h plv8.so: v8  - $(AUTOV8_DEPOT_TOOLS): - mkdir -p build - cd build; git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git  - $(AUTOV8_DIR): $(AUTOV8_DEPOT_TOOLS) - cd build; fetch v8; cd v8; git checkout $(AUTOV8_VERSION); gclient sync ; tools/dev/v8gen.py x64.release -- $(V8_OPTIONS)  - $(AUTOV8_OUT)/third_party/icu/common/icudtb.dat: - $(AUTOV8_OUT)/third_party/icu/common/icudtl.dat: - v8: $(AUTOV8_DIR) - cd $(AUTOV8_DIR) ; env CXXFLAGS=-fPIC CFLAGS=-fPIC ninja -C out.gn/x64.release d8  include Makefile.shared CCFLAGS += -I$(AUTOV8_DIR)/include -I$(AUTOV8_DIR) # We're gonna build static link. Rip it out after include Makefile SHLIB_LINK := $(filter-out -lv8, $(SHLIB_LINK))  ifeq ($(OS),Windows_NT) # noop for now else  SHLIB_LINK += -L$(AUTOV8_OUT) UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Darwin) CCFLAGS += -stdlib=libc++ -std=c++11 SHLIB_LINK += -stdlib=libc++ endif ifeq ($(UNAME_S),Linux) CCFLAGS += -std=c++11 - SHLIB_LINK += -lrt -std=c++11 -lc++ + SHLIB_LINK += -lrt -std=c++11 -lc++ -lunwind  endif endif 
Enter fullscreen mode Exit fullscreen mode

Building plv8

make 
Enter fullscreen mode Exit fullscreen mode

Installing postgres extension

sudo make install 
Enter fullscreen mode Exit fullscreen mode

run

sudo su - postgres psql 
Enter fullscreen mode Exit fullscreen mode
CREATE EXTENSION plv8; SELECT plv8_version(); 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)