Skip to content

Commit

Permalink
Fix WASMEDGE_ID bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Harrm committed Aug 26, 2024
1 parent 565921f commit c09570a
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 14 deletions.
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 =
std::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

0 comments on commit c09570a

Please sign in to comment.