From ea895eebe56c71b3a880766f7b48b815cb1cb83e Mon Sep 17 00:00:00 2001 From: Henry Date: Sun, 12 Apr 2026 21:45:10 +0200 Subject: test: fix rust warm example build Signed-off-by: Henry --- crates/parser/src/module.rs | 4 ++-- examples/rust/Cargo.toml | 2 +- examples/rust/src/tinywasm.rs | 18 ++++++++---------- examples/rust/src/tinywasm_no_std.rs | 26 +++++++++++--------------- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/crates/parser/src/module.rs b/crates/parser/src/module.rs index 8405c6d..b53dfd6 100644 --- a/crates/parser/src/module.rs +++ b/crates/parser/src/module.rs @@ -158,9 +158,9 @@ impl ModuleReader { validator.end(offset)?; self.end_reached = true; } - Payload::CustomSection(reader) => { + Payload::CustomSection(_reader) => { debug!("Found custom section"); - debug!("Skipping custom section: {:?}", reader.name()); + debug!("Skipping custom section: {:?}", _reader.name()); } Payload::UnknownSection { .. } => return Err(ParseError::UnsupportedSection("Unknown section".into())), section => return Err(ParseError::UnsupportedSection(format!("Unsupported section: {section:?}"))), diff --git a/examples/rust/Cargo.toml b/examples/rust/Cargo.toml index 6bf8a8f..73aa815 100644 --- a/examples/rust/Cargo.toml +++ b/examples/rust/Cargo.toml @@ -12,7 +12,7 @@ edition="2021" [dependencies] tinywasm={path="../../crates/tinywasm", default-features=false, features=["parser", "archive"]} argon2={version="0.5"} -lol_alloc="0.4.1" +dlmalloc={version="0.2", features=["global"]} [features] default=["std"] diff --git a/examples/rust/src/tinywasm.rs b/examples/rust/src/tinywasm.rs index 7de0dbc..0ccb026 100644 --- a/examples/rust/src/tinywasm.rs +++ b/examples/rust/src/tinywasm.rs @@ -14,19 +14,17 @@ pub extern "C" fn hello() { fn run() -> tinywasm::Result<()> { let module = tinywasm::Module::parse_stream(&include_bytes!("./print.wasm")[..])?; let mut store = tinywasm::Store::default(); + + let printi32 = HostFunction::from(&mut store, |_: FuncContext<'_>, v: i32| { + unsafe { printi32(v) } + Ok(()) + }); + let mut imports = tinywasm::Imports::new(); + imports.define("env", "printi32", printi32); - imports.define( - "env", - "printi32", - HostFunction::from(&mut store, |_: FuncContext<'_>, v: i32| { - unsafe { printi32(v) } - Ok(()) - }), - )?; let instance = module.instantiate(&mut store, Some(imports))?; - - let add_and_print = instance.func_typed::<(i32, i32), ()>(&store, "add_and_print")?; + let add_and_print = instance.func::<(i32, i32), ()>(&store, "add_and_print")?; add_and_print.call(&mut store, (1, 2))?; Ok(()) } diff --git a/examples/rust/src/tinywasm_no_std.rs b/examples/rust/src/tinywasm_no_std.rs index 5444280..6d7e73c 100644 --- a/examples/rust/src/tinywasm_no_std.rs +++ b/examples/rust/src/tinywasm_no_std.rs @@ -1,20 +1,19 @@ #![no_main] #![no_std] -use lol_alloc::{AssumeSingleThreaded, FreeListAllocator}; +use dlmalloc::GlobalDlmalloc; use tinywasm::{FuncContext, HostFunction}; extern crate alloc; +#[global_allocator] +static ALLOCATOR: GlobalDlmalloc = GlobalDlmalloc; + #[cfg(not(feature = "std"))] #[panic_handler] fn panic(_info: &core::panic::PanicInfo) -> ! { loop {} } -#[global_allocator] -static ALLOCATOR: AssumeSingleThreaded = - unsafe { AssumeSingleThreaded::new(FreeListAllocator::new()) }; - #[link(wasm_import_module = "env")] unsafe extern "C" { fn printi32(x: i32); @@ -33,17 +32,14 @@ fn run() -> tinywasm::Result<()> { let twasm = res.serialize_twasm()?; let module = tinywasm::Module::parse_bytes(&twasm)?; - imports.define( - "env", - "printi32", - HostFunction::from(&mut store, |_: FuncContext<'_>, v: i32| { - unsafe { printi32(v) } - Ok(()) - }), - )?; - let instance = module.instantiate(&mut store, Some(imports))?; + let printi32 = HostFunction::from(&mut store, |_: FuncContext<'_>, v: i32| { + unsafe { printi32(v) } + Ok(()) + }); - let add_and_print = instance.func_typed::<(i32, i32), ()>(&store, "add_and_print")?; + imports.define("env", "printi32", printi32); + let instance = module.instantiate(&mut store, Some(imports))?; + let add_and_print = instance.func::<(i32, i32), ()>(&store, "add_and_print")?; add_and_print.call(&mut store, (1, 2))?; Ok(()) } -- cgit v1.3.1