You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, there are two methods in wasi.js for initializaing, start(instance) and initialize(instance). The former requires the wasm guest to have a _start method and no _initialize, the latter will use _initialize if present and will fail if _start is present.
The wasi library is initializing the host side that is imported by a wasm guest. Because the guest may be compiled in any language targeting wasm, there actually isn't much control by the host on what initialization method gets included in the final binary. This means that for a host supporting general wasm binaries, there is this required boilerplate for initialization
if (exports['_start']) {
wasi.start(instance);
} else {
wasi.initialize(instance);
}
I think it would be more user friendly with just one way to initialize. Notably, this is to prevent the bug of calling neither method - wasi will not function if it is not initialized to wire up Memory from the guest. Anecdotally, my first experience with this API was using binaries without _start or _initialize, so I didn't call either, missing the fact that wasi.initialize is appropriate and required to be called in this case for Memory.
What is the feature you are proposing to solve the problem?
Remove wasi.start() and only have wasi.initialize(). The behavior would be
Wire up Memory
If both _start and _initialize are defined, throw an error
If _start is defined, call it
If _initialize is defined, call it
Notably, if neither is defined, it will still wire up Memory and function correctly. I'm not aware of any potential ambiguous case from having only this one entry point.
If the approach seems reasonable, happy to send a PR for it.
What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered:
Thanks for the link @devsnek, I had missed the point about the exit code in _start which is another difference between the two. Unfortunately compilers like TinyGo and maybe others do use _start even for reactors, but perhaps then the boiler plate is the only way to handle this. Hopefully the spec will make this simpler in the future.
What is the problem this feature will solve?
Currently, there are two methods in
wasi.js
for initializaing,start(instance)
andinitialize(instance)
. The former requires the wasm guest to have a_start
method and no_initialize
, the latter will use_initialize
if present and will fail if_start
is present.The wasi library is initializing the host side that is imported by a wasm guest. Because the guest may be compiled in any language targeting wasm, there actually isn't much control by the host on what initialization method gets included in the final binary. This means that for a host supporting general wasm binaries, there is this required boilerplate for initialization
I think it would be more user friendly with just one way to initialize. Notably, this is to prevent the bug of calling neither method - wasi will not function if it is not initialized to wire up
Memory
from the guest. Anecdotally, my first experience with this API was using binaries without_start
or_initialize
, so I didn't call either, missing the fact thatwasi.initialize
is appropriate and required to be called in this case forMemory
.What is the feature you are proposing to solve the problem?
Remove
wasi.start()
and only havewasi.initialize()
. The behavior would beMemory
_start
and_initialize
are defined, throw an error_start
is defined, call it_initialize
is defined, call itNotably, if neither is defined, it will still wire up
Memory
and function correctly. I'm not aware of any potential ambiguous case from having only this one entry point.If the approach seems reasonable, happy to send a PR for it.
What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered: