Skip to content

Commit 69f34bf

Browse files
committed
bump wamr to 2.1.1 and able to consume precompiled content
- skip leading paddings in .aot section Signed-off-by: [email protected] <[email protected]>
1 parent 5753265 commit 69f34bf

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

bazel/external/wamr.BUILD

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ cmake(
2626
"-DWAMR_BUILD_INTERP=0",
2727
"-DWAMR_BUILD_JIT=1",
2828
"-DWAMR_BUILD_SIMD=1",
29+
# linux perf. only for jit and aot
30+
# "-DWAMR_BUILD_LINUX_PERF=1",
2931
],
3032
"//conditions:default": [
3133
"-DWAMR_BUILD_AOT=0",

bazel/repositories.bzl

+4-4
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@ def proxy_wasm_cpp_host_repositories():
197197
http_archive,
198198
name = "com_github_bytecodealliance_wasm_micro_runtime",
199199
build_file = "@proxy_wasm_cpp_host//bazel/external:wamr.BUILD",
200-
# WAMR-1.2.1
201-
sha256 = "7548d4bbea8dbb9b005e83bd571f93a12fb3f0b5e87a8b0130f004dd92df4b0b",
202-
strip_prefix = "wasm-micro-runtime-WAMR-1.2.1",
203-
url = "https://github.com/bytecodealliance/wasm-micro-runtime/archive/refs/tags/WAMR-1.2.1.zip",
200+
# WAMR-2.1.1
201+
sha256 = "a0824762abbcbb3dd6b7bb07530f198ece5d792a12a879bc2a99100590fdb151",
202+
strip_prefix = "wasm-micro-runtime-WAMR-2.1.1",
203+
url = "https://github.com/bytecodealliance/wasm-micro-runtime/archive/refs/tags/WAMR-2.1.1.zip",
204204
)
205205

206206
native.bind(

src/wamr/wamr.cc

+22-7
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class Wamr : public WasmVm {
5656
Wamr() = default;
5757

5858
std::string_view getEngineName() override { return "wamr"; }
59-
std::string_view getPrecompiledSectionName() override { return ""; }
59+
// has to use the same name provided to test-tools/append-aot-to-wasm/append_aot_to_wasm.py
60+
std::string_view getPrecompiledSectionName() override { return "aot"; }
6061

6162
Cloneable cloneable() override { return Cloneable::CompiledBytecode; }
6263
std::unique_ptr<WasmVm> clone() override;
@@ -118,18 +119,32 @@ class Wamr : public WasmVm {
118119
std::unordered_map<std::string, WasmFuncPtr> module_functions_;
119120
};
120121

121-
bool Wamr::load(std::string_view bytecode, std::string_view /*precompiled*/,
122+
bool Wamr::load(std::string_view bytecode, std::string_view precompiled,
122123
const std::unordered_map<uint32_t, std::string> & /*function_names*/) {
123124
store_ = wasm_store_new(engine());
124125
if (store_ == nullptr) {
125126
return false;
126127
}
127128

128-
wasm_byte_vec_t binary = {.size = bytecode.size(),
129-
.data = (char *)bytecode.data(),
130-
.num_elems = bytecode.size(),
131-
.size_of_elem = sizeof(byte_t),
132-
.lock = nullptr};
129+
wasm_byte_vec_t binary = {0};
130+
if (precompiled.empty()) {
131+
binary.size = bytecode.size();
132+
binary.data = (char *)bytecode.data();
133+
binary.num_elems = bytecode.size();
134+
binary.size_of_elem = sizeof(byte_t);
135+
binary.lock = nullptr;
136+
} else {
137+
// skip leading paddings
138+
unsigned padding_count = precompiled[0];
139+
precompiled.remove_prefix(padding_count + 1);
140+
141+
binary.size = precompiled.size();
142+
binary.data = (char *)precompiled.data();
143+
binary.num_elems = precompiled.size();
144+
binary.size_of_elem = sizeof(byte_t);
145+
binary.lock = nullptr;
146+
}
147+
133148
module_ = wasm_module_new(store_.get(), &binary);
134149
if (module_ == nullptr) {
135150
return false;

0 commit comments

Comments
 (0)