Coder Social home page Coder Social logo

v8-go-binding's Introduction

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 - 58 (see the .travis.yml file for specific versions). For example, Chrome 58 (dev branch) uses v8 5.8.244 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:

v8-go-binding's People

Contributors

augustoroman avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.