Skip to content

Commit 0a59fbd

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 772ded2 commit 0a59fbd

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
@@ -37,6 +37,8 @@ cmake(
3737
"-DWAMR_BUILD_INTERP=0",
3838
"-DWAMR_BUILD_JIT=1",
3939
"-DWAMR_BUILD_SIMD=1",
40+
# linux perf. only for jit and aot
41+
# "-DWAMR_BUILD_LINUX_PERF=1",
4042
],
4143
"//conditions:default": [
4244
"-DWAMR_BUILD_AOT=0",

bazel/repositories.bzl

+5-4
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,18 @@ 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.3.1
201-
sha256 = "4e34db792332f385fd479e1265d5eaa56705d7cf7ff3fd7734f536466aa29355",
202-
strip_prefix = "wasm-micro-runtime-WAMR-1.3.1",
203-
url = "https://github.com/bytecodealliance/wasm-micro-runtime/archive/refs/tags/WAMR-1.3.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(
207207
name = "wamr",
208208
actual = "@com_github_bytecodealliance_wasm_micro_runtime//:wamr_lib",
209209
)
210210

211+
#TODO: switch to the system pre-installed building. still 15.0.7 for sure
211212
maybe(
212213
http_archive,
213214
name = "llvm-15_0_7",

src/wamr/wamr.cc

+21-7
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class Wamr : public WasmVm {
5959
Wamr() = default;
6060

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

6465
Cloneable cloneable() override { return Cloneable::CompiledBytecode; }
6566
std::unique_ptr<WasmVm> clone() override;
@@ -121,18 +122,31 @@ class Wamr : public WasmVm {
121122
std::unordered_map<std::string, WasmFuncPtr> module_functions_;
122123
};
123124

124-
bool Wamr::load(std::string_view bytecode, std::string_view /*precompiled*/,
125+
bool Wamr::load(std::string_view bytecode, std::string_view precompiled,
125126
const std::unordered_map<uint32_t, std::string> & /*function_names*/) {
126127
store_ = wasm_store_new(engine());
127128
if (store_ == nullptr) {
128129
return false;
129130
}
130131

131-
wasm_byte_vec_t binary = {.size = bytecode.size(),
132-
.data = (char *)bytecode.data(),
133-
.num_elems = bytecode.size(),
134-
.size_of_elem = sizeof(byte_t),
135-
.lock = nullptr};
132+
wasm_byte_vec_t binary = {0};
133+
if (precompiled.empty()) {
134+
binary.size = bytecode.size();
135+
binary.data = (char *)bytecode.data();
136+
binary.num_elems = bytecode.size();
137+
binary.size_of_elem = sizeof(byte_t);
138+
binary.lock = nullptr;
139+
} else {
140+
// skip leading paddings
141+
unsigned padding_count = precompiled[0];
142+
precompiled.remove_prefix(padding_count + 1);
143+
144+
binary.size = precompiled.size();
145+
binary.data = (char *)precompiled.data();
146+
binary.num_elems = precompiled.size();
147+
binary.size_of_elem = sizeof(byte_t);
148+
binary.lock = nullptr;
149+
}
136150

137151
module_ = wasm_module_new(store_.get(), &binary);
138152
if (module_ == nullptr) {

0 commit comments

Comments
 (0)