Skip to content

Commit 397d194

Browse files
committed
WasmEdge: Update the WasmEdge runtime to WasmEdge-0.9.0.
Signed-off-by: YiYing He <[email protected]>
1 parent 1f06057 commit 397d194

File tree

4 files changed

+62
-47
lines changed

4 files changed

+62
-47
lines changed

bazel/external/wasmedge.BUILD

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
1-
load("@rules_cc//cc:defs.bzl", "cc_library")
1+
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
22

33
licenses(["notice"]) # Apache 2
44

55
package(default_visibility = ["//visibility:public"])
66

7-
cc_library(
7+
filegroup(
8+
name = "srcs",
9+
srcs = glob(["**"]),
10+
)
11+
12+
cmake(
813
name = "wasmedge_lib",
9-
srcs = ["lib64/libwasmedge_c.so"],
10-
hdrs = ["include/wasmedge.h"],
11-
strip_include_prefix = "include/",
14+
cache_entries = {
15+
# "LLVM_DIR": "$EXT_BUILD_DEPS/copy_llvm/llvm/lib/cmake/llvm",
16+
"WASMEDGE_BUILD_AOT_RUNTIME": "Off",
17+
"WASMEDGE_BUILD_SHARED_LIB": "Off",
18+
"WASMEDGE_BUILD_STATIC_LIB": "On",
19+
"WASMEDGE_BUILD_TOOLS": "Off",
20+
"WASMEDGE_FORCE_DISABLE_LTO": "On",
21+
},
22+
env_vars = {
23+
# Workaround for the -DDEBUG flag added in fastbuild on macOS,
24+
# which conflicts with DEBUG macro used in LLVM.
25+
"CFLAGS": "-UDEBUG",
26+
"CXXFLAGS": "-UDEBUG",
27+
"ASMFLAGS": "-UDEBUG",
28+
},
29+
generate_args = ["-GNinja"],
30+
lib_source = ":srcs",
31+
out_static_libs = [
32+
"libwasmedge_c.a"
33+
],
1234
)

bazel/repositories.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def proxy_wasm_cpp_host_repositories():
115115
http_archive(
116116
name = "com_github_wasmedge_wasmedge",
117117
build_file = "@proxy_wasm_cpp_host//bazel/external:wasmedge.BUILD",
118-
sha256 = "48c15893f036b86b0f28d96e6269a4ac75d9697a30c44b171e254c83409afb30",
119-
strip_prefix = "WasmEdge-0.8.2-Linux",
120-
url = "https://github.com/WasmEdge/WasmEdge/releases/download/0.8.2/WasmEdge-0.8.2-manylinux2014_x86_64.tar.gz",
118+
sha256 = "e7c86b397aa2d5e712cd06af9fe1ed5604fe7d1d6dedbc6d62c846dd0131953d",
119+
strip_prefix = "WasmEdge-f34286ea920eefa9884ee31f7c509aa8bd99aec3",
120+
url = "https://github.com/WasmEdge/WasmEdge/archive/f34286ea920eefa9884ee31f7c509aa8bd99aec3.tar.gz",
121121
)
122122

123123
native.bind(

src/wasmedge/types.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "src/common/types.h"
16-
#include "wasmedge.h"
16+
#include "wasmedge/wasmedge.h"
1717

1818
namespace proxy_wasm {
1919
namespace WasmEdge {
@@ -22,8 +22,7 @@ using WasmEdgeStorePtr = common::CSmartPtr<WasmEdge_StoreContext, WasmEdge_Store
2222
using WasmEdgeVMPtr = common::CSmartPtr<WasmEdge_VMContext, WasmEdge_VMDelete>;
2323
using WasmEdgeLoaderPtr = common::CSmartPtr<WasmEdge_LoaderContext, WasmEdge_LoaderDelete>;
2424
using WasmEdgeValidatorPtr = common::CSmartPtr<WasmEdge_ValidatorContext, WasmEdge_ValidatorDelete>;
25-
using WasmEdgeInterpreterPtr =
26-
common::CSmartPtr<WasmEdge_InterpreterContext, WasmEdge_InterpreterDelete>;
25+
using WasmEdgeExecutorPtr = common::CSmartPtr<WasmEdge_ExecutorContext, WasmEdge_ExecutorDelete>;
2726
using WasmEdgeASTModulePtr = common::CSmartPtr<WasmEdge_ASTModuleContext, WasmEdge_ASTModuleDelete>;
2827

2928
} // namespace WasmEdge

src/wasmedge/wasmedge.cc

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "include/proxy-wasm/wasm_vm.h"
1818
#include "src/wasmedge/types.h"
1919

20-
#include "wasmedge.h"
20+
#include "wasmedge/wasmedge.h"
2121

2222
#include <array>
2323
#include <cassert>
@@ -206,11 +206,10 @@ namespace WasmEdge {
206206
struct HostFuncData {
207207
HostFuncData(const std::string_view modname, const std::string_view name)
208208
: modname_(modname), name_(name) {}
209-
~HostFuncData() { WasmEdge_FunctionTypeDelete(functype_); }
209+
~HostFuncData() {}
210210

211211
std::string modname_, name_;
212-
WasmEdge_WrapFunc_t callback_;
213-
WasmEdge_FunctionTypeContext *functype_;
212+
WasmEdge_HostFunc_t callback_;
214213
void *raw_func_;
215214
WasmVm *vm_;
216215
};
@@ -219,8 +218,7 @@ using HostFuncDataPtr = std::unique_ptr<HostFuncData>;
219218

220219
struct HostModuleData {
221220
HostModuleData(const std::string_view modname) {
222-
cxt_ =
223-
WasmEdge_ImportObjectCreate(WasmEdge_StringWrap(modname.data(), modname.length()), nullptr);
221+
cxt_ = WasmEdge_ImportObjectCreate(WasmEdge_StringWrap(modname.data(), modname.length()));
224222
}
225223
~HostModuleData() { WasmEdge_ImportObjectDelete(cxt_); }
226224

@@ -234,7 +232,7 @@ class WasmEdge : public WasmVm {
234232
WasmEdge() {
235233
loader_ = WasmEdge_LoaderCreate(nullptr);
236234
validator_ = WasmEdge_ValidatorCreate(nullptr);
237-
interpreter_ = WasmEdge_InterpreterCreate(nullptr, nullptr);
235+
executor_ = WasmEdge_ExecutorCreate(nullptr, nullptr);
238236
store_ = nullptr;
239237
module_ = nullptr;
240238
memory_ = nullptr;
@@ -289,7 +287,7 @@ class WasmEdge : public WasmVm {
289287

290288
WasmEdgeLoaderPtr loader_;
291289
WasmEdgeValidatorPtr validator_;
292-
WasmEdgeInterpreterPtr interpreter_;
290+
WasmEdgeExecutorPtr executor_;
293291
WasmEdgeStorePtr store_;
294292
WasmEdgeASTModulePtr module_;
295293
WasmEdge_MemoryInstanceContext *memory_;
@@ -319,16 +317,15 @@ bool WasmEdge::link(std::string_view debug_name) {
319317
// Create store and register imports.
320318
store_ = WasmEdge_StoreCreate();
321319
for (auto &&it : import_objects_) {
322-
auto res =
323-
WasmEdge_InterpreterRegisterImport(interpreter_.get(), store_.get(), it.second->cxt_);
320+
auto res = WasmEdge_ExecutorRegisterImport(executor_.get(), store_.get(), it.second->cxt_);
324321
if (!WasmEdge_ResultOK(res)) {
325322
fail(FailState::UnableToInitializeCode,
326323
std::string("Failed to link Wasm module due to import: ") + it.first);
327324
return false;
328325
}
329326
}
330327
// Instantiate module.
331-
if (auto res = WasmEdge_InterpreterInstantiate(interpreter_.get(), store_.get(), module_.get());
328+
if (auto res = WasmEdge_ExecutorInstantiate(executor_.get(), store_.get(), module_.get());
332329
!WasmEdge_ResultOK(res)) {
333330
fail(FailState::UnableToInitializeCode,
334331
std::string("Failed to link Wasm module: ") + std::string(WasmEdge_ResultGetMessage(res)));
@@ -345,7 +342,6 @@ bool WasmEdge::link(std::string_view debug_name) {
345342
WasmEdge_StoreListFunction(store_.get(), &names[0], num);
346343
for (auto i = 0; i < num; i++) {
347344
module_functions_.insert(std::string(names[i].Buf, names[i].Length));
348-
WasmEdge_StringDelete(names[i]);
349345
}
350346
}
351347
return true;
@@ -402,13 +398,12 @@ void WasmEdge::registerHostFunctionImpl(std::string_view module_name,
402398
}
403399

404400
auto data = std::make_unique<HostFuncData>(module_name, function_name);
401+
auto *func_type = newWasmEdgeFuncType<std::tuple<Args...>>();
405402
data->vm_ = this;
406-
data->functype_ = newWasmEdgeFuncType<std::tuple<Args...>>();
407403
data->raw_func_ = reinterpret_cast<void *>(function);
408-
data->callback_ = [](void *func, void *data, WasmEdge_MemoryInstanceContext *MemCxt,
409-
const WasmEdge_Value *Params, const uint32_t ParamLen,
410-
WasmEdge_Value *Returns, const uint32_t ReturnLen) -> WasmEdge_Result {
411-
auto func_data = reinterpret_cast<HostFuncData *>(func);
404+
data->callback_ = [](void *data, WasmEdge_MemoryInstanceContext *MemCxt,
405+
const WasmEdge_Value *Params, WasmEdge_Value *Returns) -> WasmEdge_Result {
406+
auto func_data = reinterpret_cast<HostFuncData *>(data);
412407
const bool log = func_data->vm_->cmpLogLevel(LogLevel::trace);
413408
if (log) {
414409
func_data->vm_->integration()->trace("[vm->host] " + func_data->modname_ + "." +
@@ -425,10 +420,10 @@ void WasmEdge::registerHostFunctionImpl(std::string_view module_name,
425420
return WasmEdge_Result_Success;
426421
};
427422

428-
auto *hostfunc_cxt =
429-
WasmEdge_HostFunctionCreateBinding(data->functype_, data->callback_, data.get(), 0);
423+
auto *hostfunc_cxt = WasmEdge_FunctionInstanceCreate(func_type, data->callback_, data.get(), 0);
424+
WasmEdge_FunctionTypeDelete(func_type);
430425

431-
WasmEdge_ImportObjectAddHostFunction(
426+
WasmEdge_ImportObjectAddFunction(
432427
it->second->cxt_, WasmEdge_StringWrap(function_name.data(), function_name.length()),
433428
hostfunc_cxt);
434429
host_functions_.insert_or_assign(std::string(module_name) + "." + std::string(function_name),
@@ -445,13 +440,12 @@ void WasmEdge::registerHostFunctionImpl(std::string_view module_name,
445440
}
446441

447442
auto data = std::make_unique<HostFuncData>(module_name, function_name);
443+
auto *func_type = newWasmEdgeFuncType<R, std::tuple<Args...>>();
448444
data->vm_ = this;
449-
data->functype_ = newWasmEdgeFuncType<R, std::tuple<Args...>>();
450445
data->raw_func_ = reinterpret_cast<void *>(function);
451-
data->callback_ = [](void *func, void *data, WasmEdge_MemoryInstanceContext *MemCxt,
452-
const WasmEdge_Value *Params, const uint32_t ParamLen,
453-
WasmEdge_Value *Returns, const uint32_t ReturnLen) -> WasmEdge_Result {
454-
auto func_data = reinterpret_cast<HostFuncData *>(func);
446+
data->callback_ = [](void *data, WasmEdge_MemoryInstanceContext *MemCxt,
447+
const WasmEdge_Value *Params, WasmEdge_Value *Returns) -> WasmEdge_Result {
448+
auto func_data = reinterpret_cast<HostFuncData *>(data);
455449
const bool log = func_data->vm_->cmpLogLevel(LogLevel::trace);
456450
if (log) {
457451
func_data->vm_->integration()->trace("[vm->host] " + func_data->modname_ + "." +
@@ -469,10 +463,10 @@ void WasmEdge::registerHostFunctionImpl(std::string_view module_name,
469463
return WasmEdge_Result_Success;
470464
};
471465

472-
auto *hostfunc_cxt =
473-
WasmEdge_HostFunctionCreateBinding(data->functype_, data->callback_, data.get(), 0);
466+
auto *hostfunc_cxt = WasmEdge_FunctionInstanceCreate(func_type, data->callback_, data.get(), 0);
467+
WasmEdge_FunctionTypeDelete(func_type);
474468

475-
WasmEdge_ImportObjectAddHostFunction(
469+
WasmEdge_ImportObjectAddFunction(
476470
it->second->cxt_, WasmEdge_StringWrap(function_name.data(), function_name.length()),
477471
hostfunc_cxt);
478472
host_functions_.insert_or_assign(std::string(module_name) + "." + std::string(function_name),
@@ -518,10 +512,10 @@ void WasmEdge::getModuleFunctionImpl(std::string_view function_name,
518512
printValues(params, sizeof...(Args)) + ")");
519513
}
520514
SaveRestoreContext saved_context(context);
521-
WasmEdge_Result res = WasmEdge_InterpreterInvoke(
522-
interpreter_.get(), store_.get(),
523-
WasmEdge_StringWrap(function_name.data(), function_name.length()), params, sizeof...(Args),
524-
nullptr, 0);
515+
WasmEdge_Result res =
516+
WasmEdge_ExecutorInvoke(executor_.get(), store_.get(),
517+
WasmEdge_StringWrap(function_name.data(), function_name.length()),
518+
params, sizeof...(Args), nullptr, 0);
525519
if (!WasmEdge_ResultOK(res)) {
526520
fail(FailState::RuntimeError, "Function: " + std::string(function_name) + " failed:\n" +
527521
WasmEdge_ResultGetMessage(res));
@@ -573,10 +567,10 @@ void WasmEdge::getModuleFunctionImpl(std::string_view function_name,
573567
printValues(params, sizeof...(Args)) + ")");
574568
}
575569
SaveRestoreContext saved_context(context);
576-
WasmEdge_Result res = WasmEdge_InterpreterInvoke(
577-
interpreter_.get(), store_.get(),
578-
WasmEdge_StringWrap(function_name.data(), function_name.length()), params, sizeof...(Args),
579-
results, 1);
570+
WasmEdge_Result res =
571+
WasmEdge_ExecutorInvoke(executor_.get(), store_.get(),
572+
WasmEdge_StringWrap(function_name.data(), function_name.length()),
573+
params, sizeof...(Args), results, 1);
580574
if (!WasmEdge_ResultOK(res)) {
581575
fail(FailState::RuntimeError, "Function: " + std::string(function_name) + " failed:\n" +
582576
WasmEdge_ResultGetMessage(res));

0 commit comments

Comments
 (0)