Skip to content

Commit a70854c

Browse files
committed
V8 stub integration.
1 parent 22cb886 commit a70854c

File tree

8 files changed

+192
-55
lines changed

8 files changed

+192
-55
lines changed

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,14 @@ if (HERA_V8)
6363
include(ProjectV8)
6464
endif()
6565

66-
if (NOT (HERA_BINARYEN OR HERA_WABT OR HERA_WAVM))
66+
if (NOT (HERA_BINARYEN OR HERA_WABT OR HERA_WAVM OR HERA_V8))
6767
message(FATAL_ERROR "At least one one engine must be enabled.")
6868
endif()
6969

7070
add_subdirectory(evmc)
7171
add_subdirectory(src)
7272
add_subdirectory(test)
7373

74-
7574
install(DIRECTORY include/hera DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
7675

7776
write_basic_package_version_file(heraConfigVersion.cmake COMPATIBILITY SameMajorVersion)

circle.yml

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
defaults:
2+
install-deps-linux: &install-deps-linux
3+
run:
4+
name: "Installing dependencies"
5+
command: |
6+
sudo apt update && sudo apt install xz-utils bzip2 pkg-config
27
38
update-submodules: &update-submodules
49
run:
@@ -51,10 +56,10 @@ defaults:
5156
destination: package
5257

5358
add-package-to-workspace: &add-package-to-workspace
54-
persist_to_workspace:
55-
root: ~/package
56-
paths:
57-
- "*"
59+
persist_to_workspace:
60+
root: ~/package
61+
paths:
62+
- "*"
5863

5964
save-deps-cache: &save-deps-cache
6065
cache-save:
@@ -160,6 +165,16 @@ defaults:
160165
testeth --version
161166
testeth -t GeneralStateTests/stEWASMTests -- --testpath tests --vm ~/build/src/libhera.$SO --singlenet Byzantium --evmc engine=wavm $TESTETH_OPTIONS
162167
168+
test-v8: &test-v8
169+
run:
170+
name: "Test shared Hera (v8)"
171+
command: |
172+
export ASAN_OPTIONS=detect_leaks=0
173+
SO=$([ $(uname) = Darwin ] && echo dylib || echo so)
174+
if [[ $PRELOAD_ASAN ]]; then export LD_PRELOAD=/usr/lib/clang/8/lib/linux/libclang_rt.asan-x86_64.so; fi
175+
testeth --version
176+
testeth -t GeneralStateTests/stEWASMTests -- --testpath tests --vm ~/build/src/libhera.$SO --singlenet Byzantium --evmc engine=v8 $TESTETH_OPTIONS
177+
163178
evmc-test: &evmc-test
164179
run:
165180
name: "Run evmc tests"
@@ -196,11 +211,12 @@ jobs:
196211
CC: clang
197212
GENERATOR: Ninja
198213
BUILD_PARALLEL_JOBS: 4
199-
CMAKE_OPTIONS: -DBUILD_SHARED_LIBS=ON -DHERA_DEBUGGING=OFF -DHERA_BINARYEN=ON -DHERA_WAVM=ON -DHERA_WABT=ON -DEVMC_TEST_TOOLS=ON
214+
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
200215
docker:
201216
- image: ethereum/cpp-build-env:9
202217
steps:
203218
- checkout
219+
- *install-deps-linux
204220
- *update-submodules
205221
- *environment-info
206222
- *restore-deps-cache
@@ -214,6 +230,7 @@ jobs:
214230
- *test-binaryen
215231
- *test-wabt
216232
- *test-wavm
233+
- *test-v8
217234
- *evmc-test
218235
- *evm2wasm-test
219236

@@ -224,13 +241,14 @@ jobs:
224241
CC: clang
225242
GENERATOR: Ninja
226243
BUILD_PARALLEL_JOBS: 4
227-
CMAKE_OPTIONS: -DBUILD_SHARED_LIBS=ON -DHERA_DEBUGGING=OFF -DHERA_BINARYEN=ON -DHERA_WAVM=ON -DHERA_WABT=ON -DEVMC_TEST_TOOLS=ON -DSANITIZE=address
244+
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
228245
# The ASan must the first loaded shared library. Force preloading it with this flag.
229246
PRELOAD_ASAN: true
230247
docker:
231248
- image: ethereum/cpp-build-env:9
232249
steps:
233250
- checkout
251+
- *install-deps-linux
234252
- *update-submodules
235253
- *environment-info
236254
- *restore-deps-cache
@@ -243,6 +261,7 @@ jobs:
243261
- *test-binaryen
244262
- *test-wabt
245263
- *test-wavm
264+
- *test-v8
246265
- *evmc-test
247266
- *evm2wasm-test
248267

@@ -253,12 +272,13 @@ jobs:
253272
- CC: gcc
254273
- GENERATOR: Unix Makefiles
255274
- BUILD_PARALLEL_JOBS: 4
256-
- CMAKE_OPTIONS: -DCOVERAGE=ON -DBUILD_SHARED_LIBS=ON -DHERA_DEBUGGING=ON -DHERA_BINARYEN=ON -DHERA_WABT=ON -DHERA_WAVM=ON
275+
- CMAKE_OPTIONS: -DCOVERAGE=ON -DBUILD_SHARED_LIBS=ON -DHERA_DEBUGGING=ON -DHERA_BINARYEN=ON -DHERA_WABT=ON -DHERA_WAVM=ON -DHERA_V8=ON
257276
- TESTETH_OPTIONS: --evmc benchmark=true
258277
docker:
259278
- image: ethereum/cpp-build-env:9
260279
steps:
261280
- checkout
281+
- *install-deps-linux
262282
- *update-submodules
263283
- *environment-info
264284
- *restore-deps-cache
@@ -271,6 +291,7 @@ jobs:
271291
- *test-binaryen
272292
- *test-wabt
273293
- *test-wavm
294+
- *test-v8
274295
- *upload-coverage-data
275296

276297
linux-gcc-static-debug:
@@ -280,11 +301,12 @@ jobs:
280301
- CC: gcc
281302
- GENERATOR: Unix Makefiles
282303
- BUILD_PARALLEL_JOBS: 4
283-
- CMAKE_OPTIONS: -DBUILD_SHARED_LIBS=OFF -DHERA_DEBUGGING=ON -DHERA_BINARYEN=ON -DHERA_WAVM=ON -DHERA_WABT=ON
304+
- CMAKE_OPTIONS: -DBUILD_SHARED_LIBS=OFF -DHERA_DEBUGGING=ON -DHERA_BINARYEN=ON -DHERA_WAVM=ON -DHERA_WABT=ON -DHERA_V8=ON
284305
docker:
285306
- image: ethereum/cpp-build-env:9
286307
steps:
287308
- checkout
309+
- *install-deps-linux
288310
- *update-submodules
289311
- *environment-info
290312
- *restore-deps-cache
@@ -299,7 +321,7 @@ jobs:
299321
- CXX: c++
300322
- GENERATOR: Unix Makefiles
301323
- BUILD_PARALLEL_JOBS: 4
302-
- CMAKE_OPTIONS: -DHERA_DEBUGGING=ON -DHERA_BINARYEN=ON -DHERA_WABT=ON
324+
- CMAKE_OPTIONS: -DHERA_DEBUGGING=ON -DHERA_BINARYEN=ON -DHERA_WABT=ON -DHERA_V8=ON
303325
macos:
304326
xcode: "10.1.0"
305327
steps:
@@ -320,6 +342,7 @@ jobs:
320342
- *fetch-tests
321343
- *test-binaryen
322344
- *test-wabt
345+
- *test-v8
323346

324347
lint:
325348
docker:

cmake/ProjectV8.cmake

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,61 @@
22
# based on https://github.com/aarlt/v8-cmake
33
#
44

5-
if(ProjectV8Included)
5+
if (ProjectV8Included)
66
return()
7-
endif()
7+
endif ()
88
set(ProjectV8Included TRUE)
99

1010
include(ExternalProject)
1111

12+
set(V8_LIBRARY ${CMAKE_BINARY_DIR}/deps/v8/out.gn/x64.release.sample/obj/${CMAKE_STATIC_LIBRARY_PREFIX}v8_monolith${CMAKE_STATIC_LIBRARY_SUFFIX})
13+
set(V8_INCLUDE ${CMAKE_BINARY_DIR}/deps/v8/include)
14+
1215
ExternalProject_Add(depot_tools
13-
GIT_REPOSITORY https://chromium.googlesource.com/chromium/tools/depot_tools.git
14-
GIT_TAG bc23ca13f1b3b684d9c2a127f33b618a71644829
15-
SOURCE_DIR "${CMAKE_BINARY_DIR}/deps/depot_tools"
16-
CONFIGURE_COMMAND ""
17-
BUILD_COMMAND ""
18-
INSTALL_COMMAND ""
19-
TEST_COMMAND ""
20-
)
21-
if (NOT EXISTS "${CMAKE_BINARY_DIR}/deps/v8/BUILD.gn")
22-
ExternalProject_Add_Step(depot_tools fetch
23-
COMMAND ${CMAKE_SOURCE_DIR}/cmake/v8_wrap.sh ${CMAKE_BINARY_DIR}/deps/depot_tools fetch v8
24-
COMMENT "fetch v8"
25-
DEPENDEES install
26-
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps"
27-
)
28-
else()
29-
ExternalProject_Add_Step(depot_tools fetch
30-
COMMAND ${CMAKE_SOURCE_DIR}/cmake/v8_wrap.sh ${CMAKE_BINARY_DIR}/deps/depot_tools gclient sync
31-
COMMENT "gclient sync"
16+
GIT_REPOSITORY https://chromium.googlesource.com/chromium/tools/depot_tools.git
17+
GIT_TAG bc23ca13f1b3b684d9c2a127f33b618a71644829
18+
SOURCE_DIR "${CMAKE_BINARY_DIR}/deps/depot_tools"
19+
CONFIGURE_COMMAND ""
20+
BUILD_COMMAND ""
21+
INSTALL_COMMAND ""
22+
TEST_COMMAND ""
23+
BUILD_BYPRODUCTS "${V8_LIBRARY}"
24+
BUILD_BYPRODUCTS "${V8_INCLUDE}"
25+
)
26+
27+
ExternalProject_Add_Step(depot_tools fetch
28+
COMMAND ${CMAKE_SOURCE_DIR}/cmake/v8_fetch.sh ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
29+
COMMENT "v8: fetch"
3230
DEPENDEES install
33-
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps/v8"
34-
)
35-
endif()
31+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps"
32+
)
3633

3734
ExternalProject_Add_Step(depot_tools v8gen
38-
COMMAND ${CMAKE_BINARY_DIR}/deps/v8/tools/dev/v8gen.py x64.release.sample
39-
COMMENT "v8gen.py x64.release.sample"
40-
DEPENDEES fetch
41-
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps/v8"
42-
)
35+
COMMAND ${CMAKE_BINARY_DIR}/deps/v8/tools/dev/v8gen.py -vv x64.release.sample
36+
COMMENT "v8: v8gen.py x64.release.sample"
37+
DEPENDEES fetch
38+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps/v8"
39+
)
4340

4441
ExternalProject_Add_Step(depot_tools ninja
45-
COMMAND ${CMAKE_BINARY_DIR}/deps/depot_tools/ninja -C out.gn/x64.release.sample v8_monolith
46-
COMMENT "ninja -C out.gn/x64.release.sample v8_monolith"
47-
DEPENDEES v8gen
48-
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps/v8"
49-
)
42+
COMMAND ${CMAKE_BINARY_DIR}/deps/depot_tools/ninja -C out.gn/x64.release.sample v8_monolith
43+
COMMENT "v8: ninja -C out.gn/x64.release.sample v8_monolith"
44+
DEPENDEES v8gen
45+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps/v8"
46+
)
5047

51-
add_library(v8 INTERFACE)
52-
add_library(v8:v8 ALIAS v8)
53-
add_dependencies(v8 v8lib depot_tools)
54-
target_include_directories(v8 INTERFACE
55-
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/deps/v8/include>
56-
$<INSTALL_INTERFACE:include>
48+
add_library(v8::v8 STATIC IMPORTED)
49+
50+
set_target_properties(
51+
v8::v8
52+
PROPERTIES
53+
IMPORTED_CONFIGURATIONS Release
54+
IMPORTED_LOCATION_RELEASE ${V8_LIBRARY}
5755
)
58-
target_link_libraries(v8
59-
INTERFACE ${CMAKE_BINARY_DIR}/deps/v8/out.gn/x64.release.sample/obj/${CMAKE_STATIC_LIBRARY_PREFIX}v8_monolith${CMAKE_STATIC_LIBRARY_SUFFIX}
56+
file(MAKE_DIRECTORY ${V8_INCLUDE})
57+
target_include_directories(v8::v8 INTERFACE
58+
$<BUILD_INTERFACE:${V8_INCLUDE}>
59+
$<INSTALL_INTERFACE:include>
6060
)
61+
62+
add_dependencies(v8::v8 depot_tools)

cmake/v8_fetch.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
CMAKE_SOURCE_DIR=$1
3+
CMAKE_BINARY_DIR=$2
4+
if [ ! -f "${CMAKE_BINARY_DIR}/deps/v8/BUILD.gn" ]
5+
then
6+
rm -rf ${CMAKE_BINARY_DIR}/deps/v8
7+
${CMAKE_SOURCE_DIR}/cmake/v8_wrap.sh ${CMAKE_BINARY_DIR}/deps/depot_tools fetch v8
8+
else
9+
mkdir -p ${CMAKE_BINARY_DIR}/deps/v8/include
10+
${CMAKE_SOURCE_DIR}/cmake/v8_wrap.sh ${CMAKE_BINARY_DIR}/deps/depot_tools gclient sync
11+
fi

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ endif()
6666

6767
if(HERA_V8)
6868
target_compile_definitions(hera PRIVATE HERA_V8=1)
69-
target_link_libraries(hera PRIVATE v8:v8)
69+
target_link_libraries(hera PRIVATE v8::v8)
7070
endif()
7171

7272
install(TARGETS hera EXPORT heraTargets

src/hera.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
#if HERA_WABT
4040
#include "wabt.h"
4141
#endif
42+
#if HERA_V8
43+
#include "v8.h"
44+
#endif
4245

4346
#include <hera/buildinfo.h>
4447

@@ -71,7 +74,10 @@ const map<string, WasmEngineCreateFn> wasm_engine_map {
7174
{ "wavm", WavmEngine::create },
7275
#endif
7376
#if HERA_WABT
74-
{ "wabt", WabtEngine::create },
77+
{ "wabt", WabtEngine::create },
78+
#endif
79+
#if HERA_V8
80+
{ "v8", V8Engine::create },
7581
#endif
7682
};
7783

@@ -83,6 +89,8 @@ WasmEngineCreateFn wasmEngineCreateFn =
8389
WabtEngine::create
8490
#elif HERA_WAVM
8591
WavmEngine::create
92+
#elif HERA_V8
93+
V8Engine::create
8694
#else
8795
#error "No engine requested."
8896
#endif

src/v8.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2019 Alexander Arlt <alexander.arlt@arlt-labs.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <iostream>
18+
19+
#include "v8.h"
20+
#include "debugging.h"
21+
#include "eei.h"
22+
#include "exceptions.h"
23+
24+
using namespace std;
25+
26+
namespace hera {
27+
28+
std::unique_ptr<WasmEngine> hera::V8Engine::create() {
29+
return nullptr;
30+
}
31+
32+
ExecutionResult hera::V8Engine::execute(evmc_context *context,
33+
bytes_view code,
34+
bytes_view state_code,
35+
const evmc_message &msg,
36+
bool meterInterfaceGas) {
37+
(void) context;
38+
(void) code;
39+
(void) state_code;
40+
(void) msg;
41+
(void) meterInterfaceGas;
42+
43+
ExecutionResult result{};
44+
return result;
45+
}
46+
47+
void hera::V8Engine::verifyContract(hera::bytes_view code) {
48+
(void) code;
49+
}
50+
51+
} // namespace hera

0 commit comments

Comments
 (0)