-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add env object to WASIContext to pass an externally defined Memory object into the WebAssembly context #277
Conversation
…ject into the WebAssembly context
Hey mate! Thanks for the PR. This is a great suggestion! Being able to specify the Memory is important. I don't want to mix up the env variables for WASI with the memory to give to WebAssembly. I think a refactor is in order to make the interface better match the NodeJS WASI interface. If you'd like to give that a shot I can help you with that. Or I'm happy to give it a go in my next available time. |
I'm happy to refactor. Can you be a bit more specific? Not sure I'm understand. I'm not familiar with the NodeJS WASI interface. is that any different than the wasi sdk? I'm building C to WASM and running in a browser environment. Can see how I'm building and linking. It looks the |
So I think the confusion here is between env in WASI and env in WebAssembly. In WASI env represents the environment variables to a CLI command (like a dotenv file). In WebAssembly env is things like memory (what you're passing through). The NodeJS API makes this more clear because you create a WASI instance and then pass it to the WebAssembly instantiate method. https://nodejs.org/api/wasi.html So in that API you would be able to specify the memory during the WebAssembly Instantiate and not how Runno forces you to do it (from the WASI layer). My goal with a refactor would be to better match that NodeJS API. |
After looking at the changes properly, I'm a bit confused about what you're trying to achieve here. I thought you were trying to specify a custom memory import, but it looks like you're overriding the memory that Runno writes to. What problem are you trying to solve? |
Could you please look at the documentation in my refactor: #278 Does that achieve what you want? |
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 Diego, could you answer my questions above? If you still want to go ahead with this we can discuss a plan.
The application might wanna define and have control over the memory. Might be JS code that wants to manipulate it. |
Okay so with the changes I just released in 0.6.0 you can specify your own memory instance when initialising the WebAssembly runner. Check out packages/wasi/README.md for instructions. If you'd just like to access the memory object exported by the binary, that is available on the WASI instance when it is instantiated with new WASI(). Have a look at the PR referenced above for what I mean. Does that solve your problem? |
Tried the PR and get the error:
My WASM code expect the memory passed through the env object. I don't have control over it since that comes imposed from the wasi-sdk and compiler / linker (clang - llvm) when using the Ideally and for max flexibility I would want control on what it's passed to |
And that's using the method I've outlined in the README?
I don't understand why the |
I tried your refactor and two problems. 1) In the docs you gotta do:
Looking at my wasm code I see:
I see the same error in the context of emscripten so not exclusive to the wasm-sdk toolchain. the 2) Also need a reference to the passed memory (as I did in my PR). Notice that if the memory is externally defined it's not longer part of the runno/packages/wasi/lib/wasi/wasi.ts Line 88 in 1fe1062
Opened a PR to fix 1. Not sure how you wanna handle 2. Open to suggestions |
Ahhh okay, that makes sense. Thanks for the extra context, super helpful! I've just merged another PR which should fix those issues for you: #281 Feel free to file a bug or discussion topic if you have any other problems. Cheers! |
Thanks for the patience. It works now! 👏 |
Yay!! Thanks for the feature request. |
My first typescript code. My type-fu is not great. Feel free to suggest alternatives.