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

Update WasmEdge to 0.14.0 #2125

Merged
merged 11 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
26 changes: 24 additions & 2 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,32 @@ hunter_config(
)

if ("${WASM_COMPILER}" STREQUAL "WasmEdge")
hunter_config(
fmt
URL
https://github.com/fmtlib/fmt/archive/refs/tags/10.2.1.tar.gz
SHA1
d223964b782d2562d6722ffe67027204c6035453
CMAKE_ARGS
CMAKE_POSITION_INDEPENDENT_CODE=TRUE
)

hunter_config(
spdlog
VERSION 1.12.0-p0
CMAKE_ARGS
SPDLOG_BUILD_PIC=ON
SPDLOG_FMT_EXTERNAL=ON
)

# hash or version, required later to separate WasmEdge
# binary cache directories from different versions
set(WASMEDGE_ID 58aea400de9179ad3e314c7e84fd4da345b8a643)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get the idea behind dedicating the id to a separate variable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is needed to use this ID in C++ code to add it to the path of the runtime cache. That way when wasmedge version will be updated, a new path to runtime caches will be generated to avoid possible conflicts between incompatible runtimes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And a variable is needed simply because we use this ID in two places in CMakeLists, and if it's not in a variable it will be forgotten in one of them when we change it.


hunter_config(
WasmEdge
URL https://github.com/qdrvm/WasmEdge/archive/refs/tags/0.13.5-qdrvm1.zip
SHA1 3637f5df6892a762606393940539c0dcb6e9c022
URL https://github.com/qdrvm/WasmEdge/archive/refs/heads/update/0.14.0.zip
SHA1 ${WASMEDGE_ID}
CMAKE_ARGS
WASMEDGE_BUILD_STATIC_LIB=ON
WASMEDGE_BUILD_SHARED_LIB=OFF
Expand Down
1 change: 0 additions & 1 deletion core/api/transport/impl/ws/ws_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include <boost/asio/dispatch.hpp>
#include <boost/beast/core/bind_handler.hpp>
#include <boost/beast/http/string_body.hpp>
#include <boost/config.hpp>

namespace boost::beast {
Expand Down
4 changes: 4 additions & 0 deletions core/network/impl/state_protocol_observer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
*/

#include "network/impl/state_protocol_observer_impl.hpp"

#include <unordered_set>

#include <boost/algorithm/string/predicate.hpp>
#include <libp2p/outcome/outcome.hpp>

#include "blockchain/block_header_repository.hpp"
#include "common/buffer.hpp"
#include "network/types/state_response.hpp"
Expand Down
1 change: 1 addition & 0 deletions core/runtime/wasm_edge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ target_link_libraries(runtime_wasm_edge
zstd::libzstd_static
WasmEdge::WasmEdge
)
target_compile_definitions(runtime_wasm_edge PRIVATE WASMEDGE_ID="${WASMEDGE_ID}")
kagome_install(runtime_wasm_edge)
41 changes: 24 additions & 17 deletions core/runtime/wasm_edge/module_factory_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "runtime/common/trie_storage_provider_impl.hpp"
#include "runtime/memory_provider.hpp"
#include "runtime/module.hpp"
#include "runtime/module_factory.hpp"
#include "runtime/module_instance.hpp"
#include "runtime/runtime_context.hpp"
#include "runtime/wasm_edge/memory_impl.hpp"
Expand Down Expand Up @@ -81,23 +82,20 @@ 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_ValTypeIsI32(v.Type)) {
return WasmEdge_ValueGetI32(v);
}
BOOST_UNREACHABLE_RETURN({});
if (WasmEdge_ValTypeIsI64(v.Type)) {
return WasmEdge_ValueGetI64(v);
}
if (WasmEdge_ValTypeIsF32(v.Type)) {
return WasmEdge_ValueGetF32(v);
}
if (WasmEdge_ValTypeIsF64(v.Type)) {
return WasmEdge_ValueGetF64(v);
}

return Error::INVALID_VALUE_TYPE;
}

inline CompilationOutcome<ConfigureContext> configureCtx() {
Expand Down Expand Up @@ -377,7 +375,7 @@ namespace kagome::runtime::wasm_edge {
if (config_.exec == ExecType::Interpreted) {
return std::nullopt;
}
return "wasmedge";
return std::string("wasmedge_") + WASMEDGE_ID;
}

CompilationOutcome<void> ModuleFactoryImpl::compile(
Expand All @@ -386,6 +384,15 @@ namespace kagome::runtime::wasm_edge {
OUTCOME_TRY(writeFileTmp(path_compiled, code));
return outcome::success();
}
std::error_code ec;
std::filesystem::create_directories(path_compiled.parent_path(), ec);
if (ec) {
return CompilationError{fmt::format(
"Compiled module destination dir '{}' does not exist and cannot be "
"created: {}",
path_compiled.parent_path().string(),
ec.message())};
}
Harrm marked this conversation as resolved.
Show resolved Hide resolved
OUTCOME_TRY(configure_ctx, configureCtx());
WasmEdge_ConfigureCompilerSetOptimizationLevel(
configure_ctx.raw(), WasmEdge_CompilerOptimizationLevel_O3);
Expand Down
15 changes: 8 additions & 7 deletions core/runtime/wasm_edge/register_host_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <unordered_set>

#include "host_api/host_api.hpp"
#include "log/logger.hpp"
#include "runtime/common/register_host_api.hpp"

namespace kagome::runtime::wasm_edge {
Expand All @@ -20,32 +21,32 @@ 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<uint32_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<uint64_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 Expand Up @@ -195,7 +196,7 @@ namespace kagome::runtime::wasm_edge {
"Attempt to call an unimplemented Host method '{}'",
reinterpret_cast<const char *>(data));
return WasmEdge_Result_Fail;
};
}

void stub_host_method(WasmEdge_ModuleInstanceContext *module,
std::string_view name,
Expand Down