Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshiyukiMineo committed Sep 18, 2015
0 parents commit 33d55b8
Show file tree
Hide file tree
Showing 27 changed files with 1,251 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.o
*.so
/.gclient
/.gclient_entries
/build
/depot_tools
/dist
/docs/html
/v8
/MANIFEST
v8eval_wrap.cxx
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: go
go:
- 1.4
os:
- osx
before_install:
- brew update
- brew install swig
install:
- go get github.com/stretchr/testify
script:
- ./build.sh test
64 changes: 64 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
cmake_minimum_required(VERSION 2.8)

project(v8eval)

option(V8EVAL_TEST "Build tests" OFF)

if(COMMAND cmake_policy)
cmake_policy(SET CMP0015 NEW)
endif(COMMAND cmake_policy)

include_directories(
v8
v8/include
v8/third_party/icu/source/i18n
v8/third_party/icu/source/common
src
test/googletest/googletest/include
)

if(APPLE)
link_directories(
v8/out/x64.release
)
endif(APPLE)

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
link_directories(
v8/out/x64.release/obj.target/tools/gyp
v8/out/x64.release/obj.target/third_party/icu
)
endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")

add_library(v8eval STATIC
src/v8eval.cxx
)

set(v8eval-cflags
-Wall
-Wendif-labels
-Werror
-Wno-missing-field-initializers
-Wno-unused-parameter
-Wshorten-64-to-32
-fPIC
-fno-exceptions
-fno-rtti
-fno-strict-aliasing
-fno-threadsafe-statics
-fstrict-aliasing
-fvisibility=hidden
-fvisibility-inlines-hidden
-gdwarf-2
-std=c++11
)

string(REPLACE ";" " " v8eval-cflags "${v8eval-cflags}")

set_target_properties(v8eval PROPERTIES
COMPILE_FLAGS "${v8eval-cflags}"
)

if(V8EVAL_TEST)
add_subdirectory(test)
endif(V8EVAL_TEST)
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM golang:1.5.1-wheezy

# install new glibc
RUN echo "deb http://ftp.debian.org/debian sid main" >> /etc/apt/sources.list
RUN apt-get update
RUN apt-get -t sid install -y libc6-dev

# install pyenv
RUN git clone git://github.com/yyuu/pyenv.git /.pyenv
ENV PYENV_ROOT /.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH

# install essentials to build python
RUN apt-get install -y build-essential
RUN apt-get install -y bzip2 libbz2-dev
RUN apt-get install -y openssl libssl-dev
RUN apt-get install -y sqlite3 libsqlite3-dev
RUN apt-get install -y libreadline6 libreadline6-dev

# install python
ENV PYVER 2.7.10
RUN pyenv install $PYVER
RUN pyenv global $PYVER

# install cmake
RUN apt-get install -y cmake

# install swig
RUN apt-get install -y autoconf automake libtool
RUN apt-get install -y libpcre3-dev
RUN apt-get install -y bison
RUN apt-get install -y g++
RUN apt-get install -y yodl
RUN git clone https://github.com/swig/swig.git
RUN cd swig && ./autogen.sh && ./configure && make && make install

# test v8eval
ADD . $GOPATH/src/github.com/sony/v8eval
RUN $GOPATH/src/github.com/sony/v8eval/build.sh test
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright 2015 Sony Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
17 changes: 17 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
include build.sh
include CMakeLists.txt
include LICENSE
include README.md

recursive-include python *.py
recursive-include python *.sh
recursive-include src *

prune build
prune depot_tools
prune docs
prune go
prune python/build
prune python/docs
prune test
prune v8
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# v8eval

Multi-language bindings to JavaScript engine V8.

Currently v8eval provides Go and Python bindings to the latest V8 and supports Linux and Mac OS X.
v8eval uses SWIG and can be extended easily for other languages.

## Pre-installation

#### Linux

See [Dockerfile](https://github.com/sony/v8eval/blob/master/Dockerfile).

#### Mac

See [.travis.yml](https://github.com/sony/v8eval/blob/master/.travis.yml).

## Installation

The installation takes several tens of minutes due to V8 build.

#### Go

```
git clone https://github.com/sony/v8eval.git $GOPATH/src/github.com/sony/v8eval
$GOPATH/src/github.com/sony/v8eval/go/build.sh install
```

#### Python

```
pip install v8eval
```

## Documentation

#### Go

See [godoc.org](http://godoc.org/github.com/sony/v8eval/go/v8eval).

#### Python

You can create the Sphinx documentation under python/docs.

```
python/build.sh docs
```

## Example

#### Go

```go
import "github.com/sony/v8eval/go/v8eval"

func Add(x, y int) int {
var v8 = v8eval.NewV8()
v8.Eval("function add(x, y) { return x + y; }", nil)

var sum int;
v8.Call("add", []int{x, y}, &sum)
return sum
}
```

#### Python

```python
import v8eval

def add(x, y):
v8 = v8eval.V8()
v8.eval('function add(x, y) { return x + y; }')
return v8.call('add', [x, y])
```

## License

The MIT License (MIT)

See [LICENSE](https://github.com/sony/v8eval/blob/master/LICENSE) for details.
102 changes: 102 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/sh

V8EVAL_ROOT=`cd $(dirname $0) && pwd`

if [ `uname` = "Linux" ] ; then
export CC=$V8EVAL_ROOT/v8/third_party/llvm-build/Release+Asserts/bin/clang
export CXX=$V8EVAL_ROOT/v8/third_party/llvm-build/Release+Asserts/bin/clang++
fi

if [ `uname` = "Darwin" ]; then
export CC=`which clang`
export CXX=`which clang++`
export CPP="`which clang` -E"
export LINK="`which clang++`"
export CC_host=`which clang`
export CXX_host=`which clang++`
export CPP_host="`which clang` -E"
export LINK_host=`which clang++`
export GYP_DEFINES="clang=1 mac_deployment_target=10.10"
fi

install_depot_tools() {
export PATH=$V8EVAL_ROOT/depot_tools:$PATH
if [ -d $V8EVAL_ROOT/depot_tools ]; then
return 0
fi

cd $V8EVAL_ROOT
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
}

install_googletest() {
if [ -d $V8EVAL_ROOT/test/googletest ]; then
return 0
fi

cd $V8EVAL_ROOT/test
git clone https://github.com/google/googletest.git
git checkout release-1.7.0
}

install_v8() {
if [ -d $V8EVAL_ROOT/v8 ]; then
return 0
fi

cd $V8EVAL_ROOT
fetch v8
cd v8 && CFLAGS="-fPIC" CXXFLAGS="-fPIC" make x64.release V=1
}

build() {
install_depot_tools
install_v8

cd $V8EVAL_ROOT
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DV8EVAL_TEST=OFF ..
make VERBOSE=1
}

build_go() {
$V8EVAL_ROOT/go/build.sh
}

build_python() {
$V8EVAL_ROOT/python/build.sh
}

docs() {
cd $V8EVAL_ROOT/docs
rm -rf ./html
doxygen

$V8EVAL_ROOT/python/build.sh docs
}

test() {
build
install_googletest

cd $V8EVAL_ROOT/build
cmake -DCMAKE_BUILD_TYPE=Release -DV8EVAL_TEST=ON ..
make VERBOSE=1
./test/v8eval-test || exit 1

cd ..
./go/build.sh test || exit 1
./python/build.sh test || exit 1
}

# dispatch subcommand
SUBCOMMAND="$1";
case "${SUBCOMMAND}" in
"" ) build ;;
"go" ) build_go ;;
"python" ) build_python ;;
"docs" ) docs ;;
"test" ) test ;;
* ) echo "unknown subcommand: ${SUBCOMMAND}"; exit 1 ;;
esac
7 changes: 7 additions & 0 deletions docs/Doxyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
PROJECT_NAME = v8eval
PROJECT_NUMBER = 0.1.3
OUTPUT_DIRECTORY = .
OUTPUT_LANGUAGE = English
EXTRACT_ALL = YES
INPUT = ../src
GENERATE_LATEX = NO
3 changes: 3 additions & 0 deletions go/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/example/example
/v8eval/v8eval.h
/v8eval/v8eval.go
Loading

0 comments on commit 33d55b8

Please sign in to comment.