Skip to content

Commit

Permalink
wasmedge recursion (#1970)
Browse files Browse the repository at this point in the history
Signed-off-by: turuslan <[email protected]>
  • Loading branch information
turuslan authored Feb 2, 2024
1 parent 6468930 commit f5cdb75
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 53 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ on:

env:
BUILD_DIR: build
CI: true
KAGOME_IN_DOCKER: 1
CTEST_OUTPUT_ON_FAILURE: 1
GITHUB_HUNTER_USERNAME: ${{ secrets.HUNTER_USERNAME }}
Expand All @@ -38,17 +37,15 @@ jobs:
with:
path: ${{ env.CACHE_PATHS }}
key: ${{ github.job }}-${{ env.CACHE_VERSION }}
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@187efd9581ed20ee4e03c0dfb9ac2cd5896c4835
with:
cmake-version: '3.25.0'
- name: install
run: ./housekeeping/macos/dependency.sh
env:
KAGOME_MAC_CI: 1
- name: build
run: ./housekeeping/make_build.sh -DCLEAR_OBJS=ON -DCOVERAGE=OFF -DWASM_COMPILER=WasmEdge -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/cxx20.cmake
env:
CI:
KAGOME_IN_DOCKER: 0
KAGOME_MAC_CI: 1
Linux:
if: ${{ !(github.ref == 'refs/heads/master' || startsWith( github.ref, 'refs/tags/' )) }}
strategy:
Expand Down
3 changes: 1 addition & 2 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ if ("${WASM_COMPILER}" STREQUAL "WasmEdge")

hunter_config(
WasmEdge
URL https://github.com/Harrm/WasmEdge/archive/f9ef1de1679dd86c62c998a28fc8875e32c187f6.zip
SHA1 2bd770546623afb6083e67a3e6bad819f36dfd72
VERSION 0.14.0-alpha.1-qdrvm2
CMAKE_ARGS
WASMEDGE_BUILD_STATIC_LIB=ON
WASMEDGE_BUILD_SHARED_LIB=OFF
Expand Down
4 changes: 2 additions & 2 deletions cmake/Hunter/hunter-gate-url.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
HunterGate(
URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.25.3-qdrvm1.tar.gz
SHA1 5fe289a63b716c51415476b531cb3648657f8485
URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.25.3-qdrvm3.zip
SHA1 8989599eaa462f367805e2d36a30150c93b1d660
LOCAL
)
13 changes: 1 addition & 12 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,7 @@ find_package(zstd CONFIG REQUIRED)

if ("${WASM_COMPILER}" STREQUAL "WasmEdge")
hunter_add_package(WasmEdge)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
find_library(WASM_EDGE_LIBRARY NAMES libwasmedged.a REQUIRED PATHS "${WASMEDGE_ROOT}")
else()
find_library(WASM_EDGE_LIBRARY NAMES libwasmedge.a REQUIRED PATHS "${WASMEDGE_ROOT}")
endif()

add_library(WasmEdge::WasmEdge STATIC IMPORTED)
set_property(TARGET WasmEdge::WasmEdge PROPERTY IMPORTED_LOCATION "${WASM_EDGE_LIBRARY}")
target_link_libraries(WasmEdge::WasmEdge INTERFACE curses zstd::libzstd_static)
if (APPLE)
target_link_libraries(WasmEdge::WasmEdge INTERFACE xar)
endif()
find_package(WasmEdge REQUIRED CONFIG)
endif ()

hunter_add_package(rocksdb)
Expand Down
1 change: 0 additions & 1 deletion core/runtime/wasm_edge/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

add_library(runtime_wasm_edge module_factory_impl.cpp memory_impl.cpp)
target_link_libraries(runtime_wasm_edge WasmEdge::WasmEdge memory_allocator)
target_include_directories(runtime_wasm_edge PRIVATE "${WASMEDGE_ROOT}/include")
kagome_install(runtime_wasm_edge)
59 changes: 34 additions & 25 deletions core/runtime/wasm_edge/module_factory_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,26 @@ namespace kagome::runtime::wasm_edge {
}

static outcome::result<WasmValue> convertValue(WasmEdge_Value v) {
switch (v.Type) {
case WasmEdge_ValType_I32:
return WasmEdge_ValueGetI32(v);
case WasmEdge_ValType_I64:
return WasmEdge_ValueGetI64(v);
case WasmEdge_ValType_F32:
return WasmEdge_ValueGetF32(v);
case WasmEdge_ValType_F64:
return WasmEdge_ValueGetF64(v);
case WasmEdge_ValType_V128:
return Error::INVALID_VALUE_TYPE;
case WasmEdge_ValType_FuncRef:
return Error::INVALID_VALUE_TYPE;
case WasmEdge_ValType_ExternRef:
return Error::INVALID_VALUE_TYPE;
if (WasmEdge_ValTypeIsEqual(v.Type, WasmEdge_ValTypeGenI32())) {
return WasmEdge_ValueGetI32(v);
}
if (WasmEdge_ValTypeIsEqual(v.Type, WasmEdge_ValTypeGenI64())) {
return WasmEdge_ValueGetI64(v);
}
if (WasmEdge_ValTypeIsEqual(v.Type, WasmEdge_ValTypeGenF32())) {
return WasmEdge_ValueGetF32(v);
}
if (WasmEdge_ValTypeIsEqual(v.Type, WasmEdge_ValTypeGenF64())) {
return WasmEdge_ValueGetF64(v);
}
if (WasmEdge_ValTypeIsEqual(v.Type, WasmEdge_ValTypeGenV128())) {
return Error::INVALID_VALUE_TYPE;
}
if (WasmEdge_ValTypeIsEqual(v.Type, WasmEdge_ValTypeGenFuncRef())) {
return Error::INVALID_VALUE_TYPE;
}
if (WasmEdge_ValTypeIsEqual(v.Type, WasmEdge_ValTypeGenExternRef())) {
return Error::INVALID_VALUE_TYPE;
}
BOOST_UNREACHABLE_RETURN({});
}
Expand Down Expand Up @@ -196,16 +201,7 @@ namespace kagome::runtime::wasm_edge {
return v;
}

void forDataSegment(const DataSegmentProcessor &callback) const override {
uint32_t segments_num =
WasmEdge_ModuleInstanceListDataSegments(instance_.raw(), nullptr, 0);
std::vector<WasmEdge_DataSegment> segments(segments_num);
WasmEdge_ModuleInstanceListDataSegments(
instance_.raw(), segments.data(), segments.size());
for (auto &segment : segments) {
callback(segment.Offset, std::span{segment.Data, segment.Length});
}
}
void forDataSegment(const DataSegmentProcessor &callback) const override;

const InstanceEnvironment &getEnvironment() const override {
return env_;
Expand Down Expand Up @@ -334,8 +330,21 @@ namespace kagome::runtime::wasm_edge {
const WasmEdge_MemoryTypeContext *memory_type_;
ASTModuleContext module_;
const common::Hash256 code_hash_;

friend class ModuleInstanceImpl;
};

void ModuleInstanceImpl::forDataSegment(
const DataSegmentProcessor &callback) const {
auto raw = dynamic_cast<const ModuleImpl &>(*module_).module_.raw();
uint32_t segments_num = WasmEdge_ASTModuleListDataSegments(raw, nullptr, 0);
std::vector<WasmEdge_DataSegment> segments(segments_num);
WasmEdge_ASTModuleListDataSegments(raw, segments.data(), segments.size());
for (auto &segment : segments) {
callback(segment.Offset, std::span{segment.Data, segment.Length});
}
}

ModuleFactoryImpl::ModuleFactoryImpl(
std::shared_ptr<const crypto::Hasher> hasher,
std::shared_ptr<host_api::HostApiFactory> host_api_factory,
Expand Down
8 changes: 4 additions & 4 deletions core/runtime/wasm_edge/register_host_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ namespace kagome::runtime::wasm_edge {

template <>
WasmEdge_ValType get_wasm_type<int32_t>() {
return WasmEdge_ValType_I32;
return WasmEdge_ValTypeGenI32();
}

template <>
WasmEdge_ValType get_wasm_type<int64_t>() {
return WasmEdge_ValType_I64;
return WasmEdge_ValTypeGenI64();
}

template <>
WasmEdge_ValType get_wasm_type<float>() {
return WasmEdge_ValType_F32;
return WasmEdge_ValTypeGenF32();
}

template <>
WasmEdge_ValType get_wasm_type<double>() {
return WasmEdge_ValType_F64;
return WasmEdge_ValTypeGenF64();
}

template <typename T>
Expand Down
6 changes: 5 additions & 1 deletion housekeeping/macos/dependency.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
# SPDX-License-Identifier: Apache-2.0
#

if [[ "${KAGOME_MAC_CI}" = 1 ]]; then
python3 -m venv ~/venv
source ~/venv/bin/activate
fi

# install python pip3 deps
pip3 install --user pyyaml
sudo python3 -m pip install --upgrade pip
sudo python3 -m pip install scikit-build
sudo python3 -m pip install cmake==3.25 requests gitpython gcovr
Expand Down
6 changes: 6 additions & 0 deletions housekeeping/make_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ if [[ "${KAGOME_IN_DOCKER}" = 1 ]]; then
source /venv/bin/activate
fi

if [[ "${KAGOME_MAC_CI}" = 1 ]]; then
source ~/venv/bin/activate
export HUNTER_PYTHON_LOCATION=$VIRTUAL_ENV
export CURL_SSL_BACKEND=SecureTransport
fi

which git

cd "$(dirname $0)/.."
Expand Down

0 comments on commit f5cdb75

Please sign in to comment.