Skip to content

Commit

Permalink
bump wamr to 2.1.1 and able to consume precompiled content
Browse files Browse the repository at this point in the history
- skip leading paddings in .aot section

Signed-off-by: [email protected] <[email protected]>
  • Loading branch information
lum1n0us committed Sep 10, 2024
1 parent 21a5b08 commit a47ab04
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
21 changes: 18 additions & 3 deletions bazel/external/wamr.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
33 changes: 24 additions & 9 deletions src/wamr/wamr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<WasmVm> clone() override;
Expand Down Expand Up @@ -118,18 +119,32 @@ class Wamr : public WasmVm {
std::unordered_map<std::string, WasmFuncPtr> 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<uint32_t, std::string> & /*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 = static_cast<char *> bytecode.data();
binary.num_elems = bytecode.size();
binary.size_of_elem = sizeof(byte_t);
binary.lock = nullptr;
} else {
// skip leading paddings
uint8_t padding_count = static_cast<uint8_t> precompiled[0];
precompiled.remove_prefix(padding_count + 1);

binary.size = precompiled.size();
binary.data = static_cast<char *> 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;
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit a47ab04

Please sign in to comment.