From 951c8070169e8bd970940029156f305e741aecdb Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Sun, 23 Aug 2026 13:40:38 +0200 Subject: chore: remove LinearMemory trait (#53) Signed-off-by: Henry --- examples/rust/Cargo.toml | 14 +++++--------- examples/rust/build.sh | 4 ++-- examples/rust/src/hello.rs | 12 +++++++----- examples/rust/src/print.rs | 4 +++- examples/rust/src/print.twasm | Bin 154 -> 154 bytes examples/rust/src/tinywasm_precompiled.rs | 30 ------------------------------ examples/wasm-rust.rs | 24 ------------------------ 7 files changed, 17 insertions(+), 71 deletions(-) delete mode 100644 examples/rust/src/tinywasm_precompiled.rs (limited to 'examples') diff --git a/examples/rust/Cargo.toml b/examples/rust/Cargo.toml index b338bd2..6701074 100644 --- a/examples/rust/Cargo.toml +++ b/examples/rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rust-wasm-examples" -edition = "2021" +edition = "2024" publish = false # treat this as an independent package @@ -22,10 +22,6 @@ path = "src/print.rs" name = "tinywasm" path = "src/tinywasm.rs" -[[bin]] -name = "tinywasm_precompiled" -path = "src/tinywasm_precompiled.rs" - [[bin]] name = "tinywasm_no_std" path = "src/tinywasm_no_std.rs" @@ -41,10 +37,10 @@ path = "src/argon2id.rs" [dependencies] argon2 = { version = "0.5" } dlmalloc = { version = "0.2", features = ["global"] } -tinywasm = { path = "../../crates/tinywasm", default-features = false, features = [ - "archive", - "parser" -] } +tinywasm = { path = "../../crates/tinywasm", default-features = false, features = ["archive", "parser"] } + +[lints.clippy] +missing_safety_doc = "allow" [features] default = ["std"] diff --git a/examples/rust/build.sh b/examples/rust/build.sh index b2a6149..cbd3b27 100755 --- a/examples/rust/build.sh +++ b/examples/rust/build.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash cd "$(dirname "$0")" || exit -bins=("host_fn" "hello" "fibonacci" "print" "tinywasm" "tinywasm_precompiled" "argon2id") -exclude_wat=("tinywasm" "tinywasm_precompiled") +bins=("host_fn" "hello" "fibonacci" "print" "tinywasm" "argon2id") +exclude_wat=("tinywasm") out_dir="./target/wasm32-unknown-unknown/wasm" dest_dir="out" diff --git a/examples/rust/src/hello.rs b/examples/rust/src/hello.rs index 3d9f400..06ef5c9 100644 --- a/examples/rust/src/hello.rs +++ b/examples/rust/src/hello.rs @@ -19,10 +19,12 @@ pub unsafe extern "C" fn arg_size() -> i32 { #[unsafe(no_mangle)] pub unsafe extern "C" fn hello(len: i32) { - let arg = core::str::from_utf8(&ARG[0..len as usize]).unwrap(); - let res = format!("Hello, {}!", arg).as_bytes().to_vec(); + unsafe { + let arg = core::str::from_utf8(&ARG[0..len as usize]).unwrap(); + let res = format!("Hello, {}!", arg).as_bytes().to_vec(); - let len = res.len() as i32; - let ptr = res.leak().as_ptr() as i64; - print_utf8(ptr, len); + let len = res.len() as i32; + let ptr = res.leak().as_ptr() as i64; + print_utf8(ptr, len); + } } diff --git a/examples/rust/src/print.rs b/examples/rust/src/print.rs index d2934f0..991ea4a 100644 --- a/examples/rust/src/print.rs +++ b/examples/rust/src/print.rs @@ -7,5 +7,7 @@ unsafe extern "C" { #[unsafe(no_mangle)] pub unsafe extern "C" fn add_and_print(lh: i32, rh: i32) { - printi32(lh + rh); + unsafe { + printi32(lh + rh); + } } diff --git a/examples/rust/src/print.twasm b/examples/rust/src/print.twasm index f0fa9a8..7841329 100644 Binary files a/examples/rust/src/print.twasm and b/examples/rust/src/print.twasm differ diff --git a/examples/rust/src/tinywasm_precompiled.rs b/examples/rust/src/tinywasm_precompiled.rs deleted file mode 100644 index bc0e0c1..0000000 --- a/examples/rust/src/tinywasm_precompiled.rs +++ /dev/null @@ -1,30 +0,0 @@ -#![no_main] -use tinywasm::{FuncContext, HostFunction, Module, ModuleInstance}; - -#[link(wasm_import_module = "env")] -unsafe extern "C" { - fn printi32(x: i32); -} - -#[unsafe(no_mangle)] -pub extern "C" fn hello() { - let _ = run(); -} - -fn run() -> tinywasm::Result<()> { - let module = Module::try_from_twasm(include_bytes!("./print.twasm"))?; - let mut store = tinywasm::Store::default(); - - let printi32 = HostFunction::from(|_: FuncContext<'_>, v: i32| { - unsafe { printi32(v) } - Ok(()) - }); - - let mut imports = tinywasm::Imports::new(); - imports.define("env", "printi32", printi32); - - let instance = ModuleInstance::instantiate(&mut store, &module, Some(&imports))?; - 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/wasm-rust.rs b/examples/wasm-rust.rs index b3398f8..0cfb0ce 100644 --- a/examples/wasm-rust.rs +++ b/examples/wasm-rust.rs @@ -35,7 +35,6 @@ fn main() -> Result<()> { println!(" host_fn"); println!(" fibonacci - calculate fibonacci(30)"); println!(" tinywasm - run printi32 inside of tinywasm inside of itself"); - println!(" tinywasm_precompiled - run a precompiled module inside of tinywasm"); println!(" tinywasm_no_std - run a precompiled module inside of no_std tinywasm"); println!(" argon2id - run argon2id(1000, 2, 1)"); return Ok(()); @@ -46,7 +45,6 @@ fn main() -> Result<()> { "printi32" => printi32()?, "fibonacci" => fibonacci()?, "tinywasm" => tinywasm()?, - "tinywasm_precompiled" => tinywasm_precompiled()?, "tinywasm_no_std" => tinywasm_no_std()?, "argon2id" => argon2id()?, "host_fn" => host_fn()?, @@ -60,8 +58,6 @@ fn main() -> Result<()> { fibonacci()?; println!("\ntinywasm.wasm:"); tinywasm()?; - println!("\ntinywasm_precompiled.wasm:"); - tinywasm_precompiled()?; println!("\ntinywasm_no_std.wasm:"); tinywasm_no_std()?; println!("argon2id.wasm:"); @@ -105,21 +101,6 @@ fn tinywasm_no_std() -> Result<()> { Ok(()) } -fn tinywasm_precompiled() -> Result<()> { - let module = tinywasm::parse_file("./examples/rust/out/tinywasm_precompiled.opt.wasm")?; - let mut store = Store::default(); - - let mut imports = Imports::new(); - imports.define("env", "printi32", HostFunction::from(|_: FuncContext<'_>, _x: i32| Ok(()))); - let instance = ModuleInstance::instantiate(&mut store, &module, Some(black_box(&imports)))?; - - let hello = instance.func::<(), ()>(&store, "hello")?; - hello.call(&mut store, black_box(()))?; - hello.call(&mut store, black_box(()))?; - hello.call(&mut store, black_box(()))?; - Ok(()) -} - fn hello() -> Result<()> { let module = tinywasm::parse_file("./examples/rust/out/hello.opt.wasm")?; let mut store = Store::default(); @@ -231,11 +212,6 @@ mod tests { tinywasm().unwrap(); } - #[test] - fn test_tinywasm_precompiled() { - tinywasm_precompiled().unwrap(); - } - #[test] fn test_tinywasm_no_std() { tinywasm_no_std().unwrap(); -- cgit v1.3.1