Skip to content
/ v8 Public
forked from augustoroman/v8

A Go API for the V8 javascript engine.

License

Notifications You must be signed in to change notification settings

nerd2/v8

 
 

Repository files navigation

V8 Bindings for Go Build Status Go Report Card GoDoc

The v8 bindings allow a user to execute javascript from within a go executable.

The bindings are tested to work with several recent v8 builds matching the Chrome builds 54 - 60 (see the .travis.yml file for specific versions). For example, Chrome 59 (dev branch) uses v8 5.9.211.4 when this was written.

Note that v8 releases match the Chrome release timeline: Chrome 48 corresponds to v8 4.8.*, Chrome 49 matches v8 4.9.*. You can see the table of current chrome and the associated v8 releases at:

http://omahaproxy.appspot.com/

Compiling

In order for the bindings to compile correctly, one needs to:

  1. Compile v8 as a static library.
  2. Let cgo know where the library is located.

Compiling v8.

Download v8: https://github.com/v8/v8/wiki/Using%20Git

Lets say you've checked out the v8 source into $V8, go-v8 into $GO_V8 and want to place the static v8 library into $GO_V8/libv8/. (For example, export GO_V8=$GOPATH/src/github.com/augustoroman/v8)

Linux

Build:

make native GYPFLAGS="-Dv8_use_external_startup_data=0 -Dv8_enable_i18n_support=0 -Dv8_enable_gdbjit=0"

If build system produces a thin archive, you want to make it into a fat one:

for lib in `find out/native/obj.target/src/ -name '*.a'`;
  do ar -t $lib | xargs ar rvs $lib.new && mv -v $lib.new $lib;
done

Symlink the libraries and include directory to the Go package dir:

ln -s `pwd`/out/native/obj.target/src ${GO_V8}/libv8
ln -s `pwd`/include ${GO_V8}/include

Mac

To build: (substitute in your OS X version: sw_vers -productVersion)

GYP_DEFINES="mac_deployment_target=10.11" \
make -j5 native GYPFLAGS="-Dv8_use_external_startup_data=0 -Dv8_enable_i18n_support=0 -Dv8_enable_gdbjit=0"

On MacOS, the resulting libraries contain debugging information by default (even though we've built the release version). As a result, the binaries are 30x larger, then they should be. Strip that to reduce the size of the archives (and build times!) very significantly:

strip -S out/native/libv8_*.a

Symlink the libraries and include directory to the Go package dir:

ln -s `pwd`/out/native ${GO_V8}/libv8
ln -s `pwd`/include ${GO_V8}/include

Reference

Also relevant is the v8 API release changes doc:

https://docs.google.com/document/d/1g8JFi8T_oAE_7uAri7Njtig7fKaPDfotU6huOa1alds/edit

Credits

This work is based off of several existing libraries:

About

A Go API for the V8 javascript engine.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 74.5%
  • C++ 19.6%
  • C 3.5%
  • Shell 2.4%