Stream: general

Topic: Wasmtime memory Rust, missing read and write functions?


view this post on Zulip AndreaEsposit (Feb 15 2021 at 11:47):

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`

view this post on Zulip bjorn3 (Feb 15 2021 at 12:07):

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.

Introduce Memory::read and Memory::write methods for accessing memory contents safely. Also adds a test and mentions the the new methods in the Memory docs. Fixes #2484. Currently most fallible me...

view this post on Zulip AndreaEsposit (Feb 15 2021 at 12:11):

Oh I see, I see, it is something very new, I am using wasmtime = "0.22.0"

view this post on Zulip AndreaEsposit (Feb 15 2021 at 12:11):

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)

view this post on Zulip bjorn3 (Feb 15 2021 at 12:15):

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.

view this post on Zulip AndreaEsposit (Feb 15 2021 at 12:19):

I see, thank you @bjorn3

view this post on Zulip AndreaEsposit (Feb 15 2021 at 12:38):

Is it the same thing for wasmtime-wasi? @bjorn3 , like, do I use the same rev number?

view this post on Zulip bjorn3 (Feb 15 2021 at 12:39):

Yes, you have to use the same rev for everything.

view this post on Zulip Till Schneidereit (Feb 15 2021 at 13:15):

FWIW, we'll do a new release this week, which will include that change

view this post on Zulip AndreaEsposit (Feb 15 2021 at 13:48):

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");

wasictxBuilderused 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

view this post on Zulip AndreaEsposit (Feb 15 2021 at 13:59):

Never mind, it is because preopened_dir returns result now.


Last updated: Nov 22 2024 at 16:03 UTC