diff --git a/bazel/external/wamr.BUILD b/bazel/external/wamr.BUILD index 8c2955d57..dcf8d87ef 100644 --- a/bazel/external/wamr.BUILD +++ b/bazel/external/wamr.BUILD @@ -12,11 +12,24 @@ filegroup( cmake( name = "wamr_lib", generate_args = [ + # disable WASI "-DWAMR_BUILD_LIBC_WASI=0", - "-DWAMR_BUILD_MULTI_MODULE=0", + "-DWAMR_BUILD_LIBC_BUILTIN=0", + # MVP + "-DWAMR_BUILD_BULK_MEMORY=1", + "-DWAMR_BUILD_REF_TYPES=1", "-DWAMR_BUILD_TAIL_CALL=1", - "-DWAMR_DISABLE_HW_BOUND_CHECK=0", - "-DWAMR_DISABLE_STACK_HW_BOUND_CHECK=1", + # WAMR private features + "-DWAMR_BUILD_MULTI_MODULE=0", + # Some tests have indicated that the following three factors have + # a minimal impact on performance. + # - Get function names from name section + "-DWAMR_BUILD_CUSTOM_NAME_SECTION=1", + "-DWAMR_BUILD_LOAD_CUSTOM_SECTION=1", + # - Show Wasm call stack if met a trap + "-DWAMR_BUILD_DUMP_CALL_STACK=1", + # Cache module files + "-DWAMR_BUILD_WASM_CACHE=0", "-GNinja", ] + select({ "@proxy_wasm_cpp_host//bazel:engine_wamr_jit": [ @@ -26,6 +39,8 @@ cmake( "-DWAMR_BUILD_INTERP=0", "-DWAMR_BUILD_JIT=1", "-DWAMR_BUILD_SIMD=1", + # linux perf. only for jit and aot + # "-DWAMR_BUILD_LINUX_PERF=1", ], "//conditions:default": [ "-DWAMR_BUILD_AOT=0", diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 2665f24d5..0bede2208 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -198,10 +198,10 @@ def proxy_wasm_cpp_host_repositories(): http_archive, name = "com_github_bytecodealliance_wasm_micro_runtime", build_file = "@proxy_wasm_cpp_host//bazel/external:wamr.BUILD", - # WAMR-1.2.1 - sha256 = "7548d4bbea8dbb9b005e83bd571f93a12fb3f0b5e87a8b0130f004dd92df4b0b", - strip_prefix = "wasm-micro-runtime-WAMR-1.2.1", - url = "https://github.com/bytecodealliance/wasm-micro-runtime/archive/refs/tags/WAMR-1.2.1.zip", + # WAMR-2.1.1 + sha256 = "a0824762abbcbb3dd6b7bb07530f198ece5d792a12a879bc2a99100590fdb151", + strip_prefix = "wasm-micro-runtime-WAMR-2.1.1", + url = "https://github.com/bytecodealliance/wasm-micro-runtime/archive/refs/tags/WAMR-2.1.1.zip", ) native.bind( diff --git a/src/wamr/wamr.cc b/src/wamr/wamr.cc index ea3d140e7..482a59bf1 100644 --- a/src/wamr/wamr.cc +++ b/src/wamr/wamr.cc @@ -56,7 +56,8 @@ class Wamr : public WasmVm { Wamr() = default; std::string_view getEngineName() override { return "wamr"; } - std::string_view getPrecompiledSectionName() override { return ""; } + // must use the exact name given by test-tools/append-aot-to-wasm/append_aot_to_wasm.py + std::string_view getPrecompiledSectionName() override { return "wamr-aot"; } Cloneable cloneable() override { return Cloneable::CompiledBytecode; } std::unique_ptr clone() override; @@ -118,18 +119,32 @@ class Wamr : public WasmVm { std::unordered_map module_functions_; }; -bool Wamr::load(std::string_view bytecode, std::string_view /*precompiled*/, +bool Wamr::load(std::string_view bytecode, std::string_view precompiled, const std::unordered_map & /*function_names*/) { store_ = wasm_store_new(engine()); if (store_ == nullptr) { return false; } - wasm_byte_vec_t binary = {.size = bytecode.size(), - .data = (char *)bytecode.data(), - .num_elems = bytecode.size(), - .size_of_elem = sizeof(byte_t), - .lock = nullptr}; + wasm_byte_vec_t binary = {0}; + if (precompiled.empty()) { + binary.size = bytecode.size(); + binary.data = const_cast(bytecode.data()); + binary.num_elems = bytecode.size(); + binary.size_of_elem = sizeof(byte_t); + binary.lock = nullptr; + } else { + // skip leading paddings + auto padding_count = static_cast(precompiled[0]); + precompiled.remove_prefix(padding_count + 1); + + binary.size = precompiled.size(); + binary.data = const_cast(precompiled.data()); + binary.num_elems = precompiled.size(); + binary.size_of_elem = sizeof(byte_t); + binary.lock = nullptr; + } + module_ = wasm_module_new(store_.get(), &binary); if (module_ == nullptr) { return false; @@ -224,8 +239,8 @@ static const char *printValKind(wasm_valkind_t kind) { return "f32"; case WASM_F64: return "f64"; - case WASM_ANYREF: - return "anyref"; + case WASM_EXTERNREF: + return "externref"; case WASM_FUNCREF: return "funcref"; default: