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 --- examples/rust/src/tinywasm.rs | 18 ++++++++---------- examples/rust/src/tinywasm_no_std.rs | 26 +++++++++++--------------- 2 files changed, 19 insertions(+), 25 deletions(-) (limited to 'examples/rust/src') 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