-
Notifications
You must be signed in to change notification settings - Fork 55
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
Wiring SharedMemory with it's corresponding bindings #255
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 |
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. |
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 |
The Wasmtime version in use was updated in #257 so if you want to rebase that should pull in all the necessary updated bindings I think |
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.
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.
1c80d97
to
098ec79
Compare
changes in the C-APO from Wasmtime runtime repo
I'm having a Seg. Fault after writing a test, still debugging it (been busy this past weeks!). Once I have fixed it, I'll update the branch and I think we should be ok to merge this. |
It looks like mypy is reporting some type errors which might be the reason for the faults? If mypy passes it may be easier to debug perhaps |
As a heads up I'm going to publish 27.0.0 in #258 but happy to do a point release with this when it's ready. |
* Adding some unit tests for shared memory
Yep, mypy has indeed captured all the problems. |
Looks good to me! Could you go ahead and add the tests here? I'd like to make sure to at least exercise some basics in CI even if more advanced testing is coming later |
Of course that I forgot to git add the test file xDDD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for this! Would you like a publish of 27.0.2 for this?
I don't have a "production" use-case for this just yet, we are investigating the potential fit for some use-cases we have, but releasing would make things a little bit easier moving forward, so it's up to you :) |
Sounds good! I'll do that in #261 |
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: