-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wiring SharedMemory with it's corresponding bindings #255
base: main
Are you sure you want to change the base?
Conversation
I have a "test case" with this code: import wasmtime
engine = wasmtime.Engine()
wasi_config = wasmtime.WasiConfig()
wasi_config.inherit_stdout()
store = wasmtime.Store(engine)
store.set_wasi(wasi_config)
wasm_file = 'my_wasi_program.wasm'
with open(wasm_file, 'rb') as f:
wasm_bytes = f.read()
module = wasmtime.Module(engine, wasm_bytes)
linker = wasmtime.Linker(engine)
linker.define_wasi()
memory_type = wasmtime.MemoryType(wasmtime.Limits(0, 4000), shared=True) # I have added `shared` here as well
memory = wasmtime.SharedMemory(engine, memory_type)
linker.define(store, "env", "memory", memory)
instance = linker.instantiate(store, module)
... This is throwing an error coming from the wasmtime runtime:
which kind of make sense, because there's no support for the "shared" flag in the |
interface in the wasmtime runtime repo
implemented in the Rust API for wasmtime. A SharedMemory is not associated to any Store, and the read/write methods from the linear memory seem to rely on the Store in order to properly operate.
Looks good to me! I think the lack of read/write on the Rust side of things is probably an oversight and so might be worth adding here eventually, but I think it's nonetheless reasonable to start here. Before landing this'll want to have a few smoke tests too to ensure that everything is wired up right |
Do you know how can I generate the |
It's unfortunately not easy at this time. Basically |
Ok, I'm resuming this, now that we have all the pieces in place for the wasmtime runtime. |
Sounds good! As a heads up CI here pulls from a release branch of Wasmtime but you should be able to pull it from the "dev" release which should have all the latest changes. |
and adjusting the shared memory arguments to match the new api, I found out that I needed to adjust other parts of the bindings that I guess have changed since the last release. In this commit, I only change the (shared) memory related ones, but I think I can adjust the rest of the c-api that has changed as well in the following commits.
After pulling lastest changes from the c-api and regenerating the bindings, I realized that I need to integrate other changes not related to the memory as well (because regenerating the bindings pull all the changes, of course). This is fine, I can do it here as well, I wouldn't expect the PR to grow a lot. |
Ah yeah no worries, happy to review that here too! |
Ok, there's a test failing but I just saw that this issue and this branch from @jder is fixing what is missing here. |
Feel free to hack around things here and/or split out the update to Wasmtime 27. I'm busy this week but I can more thoroughly dig in next week |
I think this is more or less what we need to have an initial support for SharedMemory.
I'll be adding tests and examples if you think I'm heading into the right direction.
TODO: