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

Fix WASMEDGE_ID bug #2194

Merged
merged 2 commits into from
Aug 27, 2024
Merged
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
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ set(CMAKE_TOOLCHAIN_FILE
"${CMAKE_SOURCE_DIR}/cmake/toolchain/cxx20.cmake"
CACHE FILEPATH "Default toolchain")

# SHA1 hash of the WasmEdge repository archive.
# Required to separate cached runtimes
# compiled with different WasmEdge versions.
set(WASMEDGE_ID 58aea400de9179ad3e314c7e84fd4da345b8a643)

include("cmake/Hunter/init.cmake")

add_compile_options(-gdwarf-4)
Expand Down
4 changes: 0 additions & 4 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ if ("${WASM_COMPILER}" STREQUAL "WasmEdge")
SPDLOG_FMT_EXTERNAL=ON
)

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

hunter_config(
WasmEdge
URL https://github.com/qdrvm/WasmEdge/archive/refs/heads/update/0.14.0.zip
Expand Down
2 changes: 1 addition & 1 deletion core/runtime/binaryen/module/module_factory_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace kagome::runtime::binaryen {
storage_{std::move(storage)},
hasher_(std::move(hasher)) {}

std::optional<std::string> ModuleFactoryImpl::compilerType() const {
std::optional<std::string_view> ModuleFactoryImpl::compilerType() const {
return std::nullopt;
}

Expand Down
2 changes: 1 addition & 1 deletion core/runtime/binaryen/module/module_factory_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace kagome::runtime::binaryen {
std::shared_ptr<crypto::Hasher> hasher);

// ModuleFactory
std::optional<std::string> compilerType() const override;
std::optional<std::string_view> compilerType() const override;
CompilationOutcome<void> compile(std::filesystem::path path_compiled,
BufferView code) const override;
CompilationOutcome<std::shared_ptr<Module>> loadCompiled(
Expand Down
2 changes: 1 addition & 1 deletion core/runtime/module_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace kagome::runtime {
* `std::nullopt` means `path_compiled` stores raw WASM code for
* interpretation.
*/
virtual std::optional<std::string> compilerType() const = 0;
virtual std::optional<std::string_view> compilerType() const = 0;

/**
* Compile `wasm` code to `path_compiled`.
Expand Down
11 changes: 8 additions & 3 deletions core/runtime/wasm_edge/module_factory_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
#include "runtime/wasm_edge/memory_impl.hpp"
#include "runtime/wasm_edge/register_host_api.hpp"
#include "runtime/wasm_edge/wrappers.hpp"
#include "utils/mkdirs.hpp"
#include "utils/read_file.hpp"
#include "utils/write_file.hpp"

static_assert(std::string_view{WASMEDGE_ID}.size() == 40,
"WASMEDGE_ID should be set to WasmEdge repository SHA1 hash");

namespace kagome::runtime::wasm_edge {
enum class Error {
INVALID_VALUE_TYPE = 1,
Expand Down Expand Up @@ -371,11 +373,14 @@ namespace kagome::runtime::wasm_edge {
BOOST_ASSERT(host_api_factory_);
}

std::optional<std::string> ModuleFactoryImpl::compilerType() const {
std::optional<std::string_view> ModuleFactoryImpl::compilerType() const {
if (config_.exec == ExecType::Interpreted) {
return std::nullopt;
}
return std::string("wasmedge_") + WASMEDGE_ID;
// version changes rarely, don't need the whole hash
static std::string versioned_str =
fmt::format("wasmedge_{}", std::string_view{WASMEDGE_ID}.substr(0, 12));
return versioned_str;
}

CompilationOutcome<void> ModuleFactoryImpl::compile(
Expand Down
2 changes: 1 addition & 1 deletion core/runtime/wasm_edge/module_factory_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace kagome::runtime::wasm_edge {
std::shared_ptr<CoreApiFactory> core_factory,
Config config);

std::optional<std::string> compilerType() const override;
std::optional<std::string_view> compilerType() const override;
CompilationOutcome<void> compile(std::filesystem::path path_compiled,
BufferView code) const override;
CompilationOutcome<std::shared_ptr<Module>> loadCompiled(
Expand Down
2 changes: 1 addition & 1 deletion core/runtime/wavm/module_factory_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace kagome::runtime::wavm {
}();
}

std::optional<std::string> ModuleFactoryImpl::compilerType() const {
std::optional<std::string_view> ModuleFactoryImpl::compilerType() const {
return "wavm";
}

Expand Down
2 changes: 1 addition & 1 deletion core/runtime/wavm/module_factory_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace kagome::runtime::wavm {
std::shared_ptr<IntrinsicModule> intrinsic_module,
std::shared_ptr<crypto::Hasher> hasher);

std::optional<std::string> compilerType() const override;
std::optional<std::string_view> compilerType() const override;
CompilationOutcome<void> compile(std::filesystem::path path_compiled,
BufferView code) const override;
CompilationOutcome<std::shared_ptr<Module>> loadCompiled(
Expand Down
2 changes: 1 addition & 1 deletion test/mock/core/runtime/module_factory_mock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace kagome::runtime {

class ModuleFactoryMock final : public ModuleFactory {
public:
MOCK_METHOD(std::optional<std::string>,
MOCK_METHOD(std::optional<std::string_view>,
compilerType,
(),
(const, override));
Expand Down
Loading