I was working with wasmtime (rust) until the point where I had to interact with the memory of my WebAssembly module. In the doc there is written about these read
and write
functions (https://docs.wasmtime.dev/api/wasmtime/struct.Memory.html#method.read), but I don't seem to have them, does anybody know if you have to export the memory in a specific way to have access to those functions?
This is the way I exported the memory:
let mem = instance.get_memory("memory").expect("memory export failed");
And this is the error I get whenever I try to use read
or write
(stuff like mem.write()
):
no method named `write` found for struct `wasmtime::Memory` in the current scope
method not found in `wasmtime::Memory`
help: items from traits can only be used if the trait is implemented and in scoperustc(E0599)
server.rs(163, 13): method not found in `wasmtime::Memory`
What version of wasmtime
do you depend on? Memory::write
was introduced in #2528, which was merged 22 days ago. Wasmtime 0.22.1 was released 27 days ago, do it doesn't include it.
Oh I see, I see, it is something very new, I am using wasmtime = "0.22.0"
How do I get to use the version with read and write? @bjorn3, like what do I have to write in cargo.toml (because in crea.io the latest version is 0.22.0)
You can use wasmtime = { git = "https://github.com/bytecodealliance/wasmtime.git", rev = "09b976e1d53a05150c7b8acd36a82b34cec787b3" }
. This will add a dependency on the (as of now) latest commit in the wasmtime repo.
I see, thank you @bjorn3
Is it the same thing for wasmtime-wasi? @bjorn3 , like, do I use the same rev number?
Yes, you have to use the same rev for everything.
FWIW, we'll do a new release this week, which will include that change
Oh I see that is great to hear!, have you guys changed how WasiCtxBuilder works (at least in the not master branch)?
let mut cx1 = WasiCtxBuilder::new();
cx1.preopened_dir(dir, ".");
let cx1 = cx1.build().expect("Problem with wasctx");
wasictxBuilder
used to be part of wasmtime-wasi but it is now part of wasi-cap-std-sync.
I get this error now:
use of moved value: `cx1`
value used here after moverustc(E0382)
server.rs(121, 13): move occurs because `cx1` has type `wasi_cap_std_sync::WasiCtxBuilder`, which does not implement the `Copy` trait
server.rs(122, 13): `cx1` moved due to this method call
server.rs(123, 19): value used here after move
This worked fine before when opened_dir
was taking a file instead of a Dir
Never mind, it is because preopened_dir returns result now.
Last updated: Nov 22 2024 at 16:03 UTC