Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wasmer support #561

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ endif()

option(HERA_WAVM "Build with WAVM" OFF)
if (HERA_WAVM)
include(ProjectWAVM)
include(ProjectWAVM)
endif()

if (NOT (HERA_BINARYEN OR HERA_WABT OR HERA_WAVM))
option(HERA_WASMER "Build with wasmer" OFF)
if (HERA_WASMER)
include(ProjectWasmer)
endif()

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

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ Please also check the build options listed in the following section.
- `-DHERA_WAVM=ON` will request the compilation of WAVM support
- `-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.

### wasmer support

*Complete support.*

[wasmer] support needs to be enabled via the following build option and requested at runtime with `engine=wavm`:

- `-DHERA_WASMER=ON`
- `cargo` is needed to build.

## Runtime options

These are to be used via EVMC `set_option`:
Expand Down Expand Up @@ -127,6 +136,7 @@ Apache 2.0
[Binaryen]: https://github.com/webassembly/binaryen
[wabt]: https://github.com/webassembly/wabt
[WAVM]: https://github.com/WAVM/WAVM
[wasmer]: https://github.com/wasmerio/wasmer
[Sentinel system contract]: https://github.com/ewasm/design/blob/master/system_contracts.md#sentinel-contract
[EVM Transcompiler]: https://github.com/ewasm/design/blob/master/system_contracts.md#evm-transcompiler
[EEI]: https://github.com/ewasm/design/blob/master/eth_interface.md
Expand Down
33 changes: 33 additions & 0 deletions cmake/ProjectWasmer.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
if(ProjectWasmerIncluded)
return()
endif()
set(ProjectWasmerIncluded TRUE)
include(ExternalProject)
include(GNUInstallDirs)

# TODO: if find LLVM 8.0+ use make capi-llvm to get better permformance
set(WASMER_BUILD_COMMAND make capi)
ExternalProject_Add(wasmer
PREFIX ${CMAKE_SOURCE_DIR}/deps
DOWNLOAD_NO_PROGRESS 1
GIT_REPOSITORY https://github.com/wasmerio/wasmer.git
GIT_TAG 63a2d8129c7ad5ca670d041859de45e01292dd12
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ""
BUILD_COMMAND ${WASMER_BUILD_COMMAND}
INSTALL_COMMAND ""
LOG_CONFIGURE 1
LOG_BUILD 1
LOG_INSTALL 1
BUILD_BYPRODUCTS <SOURCE_DIR>/target/release/libwasmer_runtime_c_api.a
)

ExternalProject_Get_Property(wasmer SOURCE_DIR)
set(WASMER_INCLUDE_DIRS ${SOURCE_DIR}/lib/)
file(MAKE_DIRECTORY ${WASMER_INCLUDE_DIRS}) # Must exist.
add_library(WASMER::runtim STATIC IMPORTED)
set(WASMER_RUNTIME_LIBRARIES ${SOURCE_DIR}/target/release/libwasmer_runtime_c_api.a)
set_property(TARGET WASMER::runtim PROPERTY IMPORTED_LOCATION ${WASMER_RUNTIME_LIBRARIES})
set_property(TARGET WASMER::runtim PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${WASMER_INCLUDE_DIRS})

add_dependencies(WASMER::runtim wasmer)
9 changes: 9 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ if(HERA_WAVM)
target_sources(hera PRIVATE wavm.cpp wavm.h)
endif()

if(HERA_WASMER)
target_sources(hera PRIVATE wasmer.cpp wasmer.h)
endif()

option(HERA_DEBUGGING "Display debugging messages during execution." ON)
if(HERA_DEBUGGING)
target_compile_definitions(hera PRIVATE HERA_DEBUGGING=1)
Expand Down Expand Up @@ -60,6 +64,11 @@ if(HERA_WAVM)
target_link_libraries(hera PRIVATE wavm::wavm)
endif()

if(HERA_WASMER)
target_compile_definitions(hera PRIVATE HERA_WASMER=1)
target_link_libraries(hera PRIVATE WASMER::runtim)
endif()

install(TARGETS hera EXPORT heraTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
2 changes: 1 addition & 1 deletion src/eei.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class EthereumInterface {
// WAVM/WABT host functions access this interface through an instance,
// which requires public methods.
// TODO: update upstream WAVM/WABT to have a context (user data) passed down.
#if HERA_WAVM == 0 && HERA_WABT == 0
#if HERA_WAVM == 0 && HERA_WABT == 0 && HERA_WASMER == 0
protected:
#endif
virtual size_t memorySize() const = 0 ;
Expand Down
8 changes: 8 additions & 0 deletions src/hera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
#if HERA_WABT
#include "wabt.h"
#endif
#if HERA_WASMER
#include "wasmer.h"
#endif

#include <hera/buildinfo.h>

Expand Down Expand Up @@ -72,6 +75,9 @@ const map<string, WasmEngineCreateFn> wasm_engine_map {
#if HERA_WABT
{ "wabt", WabtEngine::create },
#endif
#if HERA_WASMER
{ "wabt", WasmerEngine::create },
#endif
};

WasmEngineCreateFn wasmEngineCreateFn =
Expand All @@ -82,6 +88,8 @@ WasmEngineCreateFn wasmEngineCreateFn =
WabtEngine::create
#elif HERA_WAVM
WavmEngine::create
#elif HERA_WASMER
WasmerEngine::create
#else
#error "No engine requested."
#endif
Expand Down
Loading