Skip to content

Commit

Permalink
V8 stub integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
aarlt committed Jun 19, 2019
1 parent 22cb886 commit 6bf0b81
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 55 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@ if (HERA_V8)
include(ProjectV8)
endif()

if (NOT (HERA_BINARYEN OR HERA_WABT OR HERA_WAVM))
if (NOT (HERA_BINARYEN OR HERA_WABT OR HERA_WAVM OR HERA_V8))
message(FATAL_ERROR "At least one one engine must be enabled.")
endif()

add_subdirectory(evmc)
add_subdirectory(src)
add_subdirectory(test)


install(DIRECTORY include/hera DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

write_basic_package_version_file(heraConfigVersion.cmake COMPATIBILITY SameMajorVersion)
Expand Down
41 changes: 32 additions & 9 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
defaults:
install-deps-linux: &install-deps-linux
run:
name: "Installing dependencies"
command: |
sudo apt update && sudo apt install -y xz-utils bzip2 pkg-config
update-submodules: &update-submodules
run:
Expand Down Expand Up @@ -51,10 +56,10 @@ defaults:
destination: package

add-package-to-workspace: &add-package-to-workspace
persist_to_workspace:
root: ~/package
paths:
- "*"
persist_to_workspace:
root: ~/package
paths:
- "*"

save-deps-cache: &save-deps-cache
cache-save:
Expand Down Expand Up @@ -160,6 +165,16 @@ defaults:
testeth --version
testeth -t GeneralStateTests/stEWASMTests -- --testpath tests --vm ~/build/src/libhera.$SO --singlenet Byzantium --evmc engine=wavm $TESTETH_OPTIONS
test-v8: &test-v8
run:
name: "Test shared Hera (v8)"
command: |
export ASAN_OPTIONS=detect_leaks=0
SO=$([ $(uname) = Darwin ] && echo dylib || echo so)
if [[ $PRELOAD_ASAN ]]; then export LD_PRELOAD=/usr/lib/clang/8/lib/linux/libclang_rt.asan-x86_64.so; fi
testeth --version
testeth -t GeneralStateTests/stEWASMTests -- --testpath tests --vm ~/build/src/libhera.$SO --singlenet Byzantium --evmc engine=v8 $TESTETH_OPTIONS
evmc-test: &evmc-test
run:
name: "Run evmc tests"
Expand Down Expand Up @@ -196,11 +211,12 @@ jobs:
CC: clang
GENERATOR: Ninja
BUILD_PARALLEL_JOBS: 4
CMAKE_OPTIONS: -DBUILD_SHARED_LIBS=ON -DHERA_DEBUGGING=OFF -DHERA_BINARYEN=ON -DHERA_WAVM=ON -DHERA_WABT=ON -DEVMC_TEST_TOOLS=ON
CMAKE_OPTIONS: -DBUILD_SHARED_LIBS=ON -DHERA_DEBUGGING=OFF -DHERA_BINARYEN=ON -DHERA_WAVM=ON -DHERA_WABT=ON -DHERA_V8=ON -DEVMC_TEST_TOOLS=ON
docker:
- image: ethereum/cpp-build-env:9
steps:
- checkout
- *install-deps-linux
- *update-submodules
- *environment-info
- *restore-deps-cache
Expand All @@ -214,6 +230,7 @@ jobs:
- *test-binaryen
- *test-wabt
- *test-wavm
- *test-v8
- *evmc-test
- *evm2wasm-test

Expand All @@ -224,13 +241,14 @@ jobs:
CC: clang
GENERATOR: Ninja
BUILD_PARALLEL_JOBS: 4
CMAKE_OPTIONS: -DBUILD_SHARED_LIBS=ON -DHERA_DEBUGGING=OFF -DHERA_BINARYEN=ON -DHERA_WAVM=ON -DHERA_WABT=ON -DEVMC_TEST_TOOLS=ON -DSANITIZE=address
CMAKE_OPTIONS: -DBUILD_SHARED_LIBS=ON -DHERA_DEBUGGING=OFF -DHERA_BINARYEN=ON -DHERA_WAVM=ON -DHERA_WABT=ON -DHERA_V8=ON -DEVMC_TEST_TOOLS=ON -DSANITIZE=address
# The ASan must the first loaded shared library. Force preloading it with this flag.
PRELOAD_ASAN: true
docker:
- image: ethereum/cpp-build-env:9
steps:
- checkout
- *install-deps-linux
- *update-submodules
- *environment-info
- *restore-deps-cache
Expand All @@ -243,6 +261,7 @@ jobs:
- *test-binaryen
- *test-wabt
- *test-wavm
- *test-v8
- *evmc-test
- *evm2wasm-test

Expand All @@ -253,12 +272,13 @@ jobs:
- CC: gcc
- GENERATOR: Unix Makefiles
- BUILD_PARALLEL_JOBS: 4
- CMAKE_OPTIONS: -DCOVERAGE=ON -DBUILD_SHARED_LIBS=ON -DHERA_DEBUGGING=ON -DHERA_BINARYEN=ON -DHERA_WABT=ON -DHERA_WAVM=ON
- CMAKE_OPTIONS: -DCOVERAGE=ON -DBUILD_SHARED_LIBS=ON -DHERA_DEBUGGING=ON -DHERA_BINARYEN=ON -DHERA_WABT=ON -DHERA_WAVM=ON -DHERA_V8=ON
- TESTETH_OPTIONS: --evmc benchmark=true
docker:
- image: ethereum/cpp-build-env:9
steps:
- checkout
- *install-deps-linux
- *update-submodules
- *environment-info
- *restore-deps-cache
Expand All @@ -271,6 +291,7 @@ jobs:
- *test-binaryen
- *test-wabt
- *test-wavm
- *test-v8
- *upload-coverage-data

linux-gcc-static-debug:
Expand All @@ -280,11 +301,12 @@ jobs:
- CC: gcc
- GENERATOR: Unix Makefiles
- BUILD_PARALLEL_JOBS: 4
- CMAKE_OPTIONS: -DBUILD_SHARED_LIBS=OFF -DHERA_DEBUGGING=ON -DHERA_BINARYEN=ON -DHERA_WAVM=ON -DHERA_WABT=ON
- CMAKE_OPTIONS: -DBUILD_SHARED_LIBS=OFF -DHERA_DEBUGGING=ON -DHERA_BINARYEN=ON -DHERA_WAVM=ON -DHERA_WABT=ON -DHERA_V8=ON
docker:
- image: ethereum/cpp-build-env:9
steps:
- checkout
- *install-deps-linux
- *update-submodules
- *environment-info
- *restore-deps-cache
Expand All @@ -299,7 +321,7 @@ jobs:
- CXX: c++
- GENERATOR: Unix Makefiles
- BUILD_PARALLEL_JOBS: 4
- CMAKE_OPTIONS: -DHERA_DEBUGGING=ON -DHERA_BINARYEN=ON -DHERA_WABT=ON
- CMAKE_OPTIONS: -DHERA_DEBUGGING=ON -DHERA_BINARYEN=ON -DHERA_WABT=ON -DHERA_V8=ON
macos:
xcode: "10.1.0"
steps:
Expand All @@ -320,6 +342,7 @@ jobs:
- *fetch-tests
- *test-binaryen
- *test-wabt
- *test-v8

lint:
docker:
Expand Down
86 changes: 44 additions & 42 deletions cmake/ProjectV8.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,61 @@
# based on https://github.com/aarlt/v8-cmake
#

if(ProjectV8Included)
if (ProjectV8Included)
return()
endif()
endif ()
set(ProjectV8Included TRUE)

include(ExternalProject)

set(V8_LIBRARY ${CMAKE_BINARY_DIR}/deps/v8/out.gn/x64.release.sample/obj/${CMAKE_STATIC_LIBRARY_PREFIX}v8_monolith${CMAKE_STATIC_LIBRARY_SUFFIX})
set(V8_INCLUDE ${CMAKE_BINARY_DIR}/deps/v8/include)

ExternalProject_Add(depot_tools
GIT_REPOSITORY https://chromium.googlesource.com/chromium/tools/depot_tools.git
GIT_TAG bc23ca13f1b3b684d9c2a127f33b618a71644829
SOURCE_DIR "${CMAKE_BINARY_DIR}/deps/depot_tools"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
if (NOT EXISTS "${CMAKE_BINARY_DIR}/deps/v8/BUILD.gn")
ExternalProject_Add_Step(depot_tools fetch
COMMAND ${CMAKE_SOURCE_DIR}/cmake/v8_wrap.sh ${CMAKE_BINARY_DIR}/deps/depot_tools fetch v8
COMMENT "fetch v8"
DEPENDEES install
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps"
)
else()
ExternalProject_Add_Step(depot_tools fetch
COMMAND ${CMAKE_SOURCE_DIR}/cmake/v8_wrap.sh ${CMAKE_BINARY_DIR}/deps/depot_tools gclient sync
COMMENT "gclient sync"
GIT_REPOSITORY https://chromium.googlesource.com/chromium/tools/depot_tools.git
GIT_TAG bc23ca13f1b3b684d9c2a127f33b618a71644829
SOURCE_DIR "${CMAKE_BINARY_DIR}/deps/depot_tools"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
BUILD_BYPRODUCTS "${V8_LIBRARY}"
BUILD_BYPRODUCTS "${V8_INCLUDE}"
)

ExternalProject_Add_Step(depot_tools fetch
COMMAND ${CMAKE_SOURCE_DIR}/cmake/v8_fetch.sh ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
COMMENT "v8: fetch"
DEPENDEES install
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps/v8"
)
endif()
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps"
)

ExternalProject_Add_Step(depot_tools v8gen
COMMAND ${CMAKE_BINARY_DIR}/deps/v8/tools/dev/v8gen.py x64.release.sample
COMMENT "v8gen.py x64.release.sample"
DEPENDEES fetch
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps/v8"
)
COMMAND ${CMAKE_BINARY_DIR}/deps/v8/tools/dev/v8gen.py -vv x64.release.sample
COMMENT "v8: v8gen.py x64.release.sample"
DEPENDEES fetch
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps/v8"
)

ExternalProject_Add_Step(depot_tools ninja
COMMAND ${CMAKE_BINARY_DIR}/deps/depot_tools/ninja -C out.gn/x64.release.sample v8_monolith
COMMENT "ninja -C out.gn/x64.release.sample v8_monolith"
DEPENDEES v8gen
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps/v8"
)
COMMAND ${CMAKE_BINARY_DIR}/deps/depot_tools/ninja -C out.gn/x64.release.sample v8_monolith
COMMENT "v8: ninja -C out.gn/x64.release.sample v8_monolith"
DEPENDEES v8gen
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps/v8"
)

add_library(v8 INTERFACE)
add_library(v8:v8 ALIAS v8)
add_dependencies(v8 v8lib depot_tools)
target_include_directories(v8 INTERFACE
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/deps/v8/include>
$<INSTALL_INTERFACE:include>
add_library(v8::v8 STATIC IMPORTED)

set_target_properties(
v8::v8
PROPERTIES
IMPORTED_CONFIGURATIONS Release
IMPORTED_LOCATION_RELEASE ${V8_LIBRARY}
)
target_link_libraries(v8
INTERFACE ${CMAKE_BINARY_DIR}/deps/v8/out.gn/x64.release.sample/obj/${CMAKE_STATIC_LIBRARY_PREFIX}v8_monolith${CMAKE_STATIC_LIBRARY_SUFFIX}
file(MAKE_DIRECTORY ${V8_INCLUDE})
target_include_directories(v8::v8 INTERFACE
$<BUILD_INTERFACE:${V8_INCLUDE}>
$<INSTALL_INTERFACE:include>
)

add_dependencies(v8::v8 depot_tools)
11 changes: 11 additions & 0 deletions cmake/v8_fetch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
CMAKE_SOURCE_DIR=$1
CMAKE_BINARY_DIR=$2
if [ ! -f "${CMAKE_BINARY_DIR}/deps/v8/BUILD.gn" ]
then
rm -rf ${CMAKE_BINARY_DIR}/deps/v8
${CMAKE_SOURCE_DIR}/cmake/v8_wrap.sh ${CMAKE_BINARY_DIR}/deps/depot_tools fetch v8
else
mkdir -p ${CMAKE_BINARY_DIR}/deps/v8/include
${CMAKE_SOURCE_DIR}/cmake/v8_wrap.sh ${CMAKE_BINARY_DIR}/deps/depot_tools gclient sync
fi
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ endif()

if(HERA_V8)
target_compile_definitions(hera PRIVATE HERA_V8=1)
target_link_libraries(hera PRIVATE v8:v8)
target_link_libraries(hera PRIVATE v8::v8)
endif()

install(TARGETS hera EXPORT heraTargets
Expand Down
10 changes: 9 additions & 1 deletion src/hera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#if HERA_WABT
#include "wabt.h"
#endif
#if HERA_V8
#include "v8.h"
#endif

#include <hera/buildinfo.h>

Expand Down Expand Up @@ -71,7 +74,10 @@ const map<string, WasmEngineCreateFn> wasm_engine_map {
{ "wavm", WavmEngine::create },
#endif
#if HERA_WABT
{ "wabt", WabtEngine::create },
{ "wabt", WabtEngine::create },
#endif
#if HERA_V8
{ "v8", V8Engine::create },
#endif
};

Expand All @@ -83,6 +89,8 @@ WasmEngineCreateFn wasmEngineCreateFn =
WabtEngine::create
#elif HERA_WAVM
WavmEngine::create
#elif HERA_V8
V8Engine::create
#else
#error "No engine requested."
#endif
Expand Down
51 changes: 51 additions & 0 deletions src/v8.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2019 Alexander Arlt <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <iostream>

#include "v8.h"
#include "debugging.h"
#include "eei.h"
#include "exceptions.h"

using namespace std;

namespace hera {

std::unique_ptr<WasmEngine> hera::V8Engine::create() {
return nullptr;
}

ExecutionResult hera::V8Engine::execute(evmc_context *context,
bytes_view code,
bytes_view state_code,
const evmc_message &msg,
bool meterInterfaceGas) {
(void) context;
(void) code;
(void) state_code;
(void) msg;
(void) meterInterfaceGas;

ExecutionResult result{};
return result;
}

void hera::V8Engine::verifyContract(hera::bytes_view code) {
(void) code;
}

} // namespace hera
Loading

0 comments on commit 6bf0b81

Please sign in to comment.