Skip to content

Commit 2b033da

Browse files
committed
add wasmer
1 parent de7390b commit 2b033da

File tree

8 files changed

+562
-3
lines changed

8 files changed

+562
-3
lines changed

CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,15 @@ endif()
5555

5656
option(HERA_WAVM "Build with WAVM" OFF)
5757
if (HERA_WAVM)
58-
include(ProjectWAVM)
58+
include(ProjectWAVM)
5959
endif()
6060

61-
if (NOT (HERA_BINARYEN OR HERA_WABT OR HERA_WAVM))
61+
option(HERA_WASMER "Build with wasmer" OFF)
62+
if (HERA_WASMER)
63+
include(ProjectWasmer)
64+
endif()
65+
66+
if (NOT (HERA_BINARYEN OR HERA_WABT OR HERA_WAVM OR HERA_WASMER))
6267
message(FATAL_ERROR "At least one one engine must be enabled.")
6368
endif()
6469

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ Please also check the build options listed in the following section.
6060
- `-DHERA_WAVM=ON` will request the compilation of WAVM support
6161
- `-DLLVM_DIR=...` one will need to specify the path to LLVM's CMake file. In most installations this has to be within the `lib/cmake/llvm` directory, such as `/usr/local/Cellar/llvm/6.0.1/lib/cmake/llvm` on Homebrew.
6262

63+
### wasmer support
64+
65+
*Complete support.*
66+
67+
[wasmer] support needs to be enabled via the following build option and requested at runtime with `engine=wavm`:
68+
69+
- `-DHERA_WASMER=ON`
70+
- `cargo` is needed to build.
71+
6372
## Runtime options
6473

6574
These are to be used via EVMC `set_option`:
@@ -127,6 +136,7 @@ Apache 2.0
127136
[Binaryen]: https://github.com/webassembly/binaryen
128137
[wabt]: https://github.com/webassembly/wabt
129138
[WAVM]: https://github.com/WAVM/WAVM
139+
[wasmer]: https://github.com/wasmerio/wasmer
130140
[Sentinel system contract]: https://github.com/ewasm/design/blob/master/system_contracts.md#sentinel-contract
131141
[EVM Transcompiler]: https://github.com/ewasm/design/blob/master/system_contracts.md#evm-transcompiler
132142
[EEI]: https://github.com/ewasm/design/blob/master/eth_interface.md

cmake/ProjectWasmer.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
if(ProjectWasmerIncluded)
2+
return()
3+
endif()
4+
set(ProjectWasmerIncluded TRUE)
5+
include(ExternalProject)
6+
include(GNUInstallDirs)
7+
8+
# TODO: if find LLVM 8.0+ use make capi-llvm to get better permformance
9+
set(WASMER_BUILD_COMMAND make capi)
10+
ExternalProject_Add(wasmer
11+
PREFIX ${CMAKE_SOURCE_DIR}/deps
12+
DOWNLOAD_NO_PROGRESS 1
13+
GIT_REPOSITORY https://github.com/wasmerio/wasmer.git
14+
GIT_TAG 63a2d8129c7ad5ca670d041859de45e01292dd12
15+
BUILD_IN_SOURCE 1
16+
CONFIGURE_COMMAND ""
17+
BUILD_COMMAND ${WASMER_BUILD_COMMAND}
18+
INSTALL_COMMAND ""
19+
LOG_CONFIGURE 1
20+
LOG_BUILD 1
21+
LOG_INSTALL 1
22+
BUILD_BYPRODUCTS <SOURCE_DIR>/target/release/libwasmer_runtime_c_api.a
23+
)
24+
25+
ExternalProject_Get_Property(wasmer SOURCE_DIR)
26+
set(WASMER_INCLUDE_DIRS ${SOURCE_DIR}/lib/)
27+
file(MAKE_DIRECTORY ${WASMER_INCLUDE_DIRS}) # Must exist.
28+
add_library(WASMER::runtim STATIC IMPORTED)
29+
set(WASMER_RUNTIME_LIBRARIES ${SOURCE_DIR}/target/release/libwasmer_runtime_c_api.a)
30+
set_property(TARGET WASMER::runtim PROPERTY IMPORTED_LOCATION ${WASMER_RUNTIME_LIBRARIES})
31+
set_property(TARGET WASMER::runtim PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${WASMER_INCLUDE_DIRS})
32+
33+
add_dependencies(WASMER::runtim wasmer)

src/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ if(HERA_WAVM)
2828
target_sources(hera PRIVATE wavm.cpp wavm.h)
2929
endif()
3030

31+
if(HERA_WASMER)
32+
target_sources(hera PRIVATE wasmer.cpp wasmer.h)
33+
endif()
34+
3135
option(HERA_DEBUGGING "Display debugging messages during execution." ON)
3236
if(HERA_DEBUGGING)
3337
target_compile_definitions(hera PRIVATE HERA_DEBUGGING=1)
@@ -60,6 +64,11 @@ if(HERA_WAVM)
6064
target_link_libraries(hera PRIVATE wavm::wavm)
6165
endif()
6266

67+
if(HERA_WASMER)
68+
target_compile_definitions(hera PRIVATE HERA_WASMER=1)
69+
target_link_libraries(hera PRIVATE WASMER::runtim)
70+
endif()
71+
6372
install(TARGETS hera EXPORT heraTargets
6473
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
6574
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}

src/eei.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class EthereumInterface {
109109
// WAVM/WABT host functions access this interface through an instance,
110110
// which requires public methods.
111111
// TODO: update upstream WAVM/WABT to have a context (user data) passed down.
112-
#if HERA_WAVM == 0 && HERA_WABT == 0
112+
#if HERA_WAVM == 0 && HERA_WABT == 0 && HERA_WASMER == 0
113113
protected:
114114
#endif
115115
virtual size_t memorySize() const = 0 ;

src/hera.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
#if HERA_WABT
3939
#include "wabt.h"
4040
#endif
41+
#if HERA_WASMER
42+
#include "wasmer.h"
43+
#endif
4144

4245
#include <hera/buildinfo.h>
4346

@@ -72,6 +75,9 @@ const map<string, WasmEngineCreateFn> wasm_engine_map {
7275
#if HERA_WABT
7376
{ "wabt", WabtEngine::create },
7477
#endif
78+
#if HERA_WASMER
79+
{ "wabt", WasmerEngine::create },
80+
#endif
7581
};
7682

7783
WasmEngineCreateFn wasmEngineCreateFn =
@@ -82,6 +88,8 @@ WasmEngineCreateFn wasmEngineCreateFn =
8288
WabtEngine::create
8389
#elif HERA_WAVM
8490
WavmEngine::create
91+
#elif HERA_WASMER
92+
WasmerEngine::create
8593
#else
8694
#error "No engine requested."
8795
#endif

0 commit comments

Comments
 (0)