-
Notifications
You must be signed in to change notification settings - Fork 73
Optionally call main() in WASI reactors as a convenience. #133
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
Conversation
WASI reactors differ from WASI commands in that they have multiple entrypoints (i.e. proxy_on_* callbacks) instead of only main(). Currently, each Proxy-Wasm SDK uses different approch to startup: - AssemblyScript SDK uses Wasm's start function. - C++ SDK creates WASI reactor with global C++ constructors taking care of early initialization and registration of plugins. - Rust SDK creates Wasm library, and suggests (via examples) using _start() function called at startup to do early initialization. Unfortunately, this is the same function name that WASI commands are using, which means that WASI constructors cannot be injected and executed at startup. - TinyGo SDK creates WASI command and calls main() at startup, but it doesn't exit after main() function returns. Calling main() in WASI reactors would allow us to prepare for when they are stablized in Rust, and to have a non-breaking fallback in case TinyGo decides to exit after main() function returns. Signed-off-by: Piotr Sikora <[email protected]>
We didn't guard |
On the other hand, we already call |
Looks good to me because this seems harmless to add. But as for TinyGo, this won't be a change since I wouldn't export |
Ah - I was confused. Maybe we would export |
TinyGo generates WASI command, which looks like this (pseudocode):
But in theory WASI command should look something like:
i.e. WASI command should exit after If TinyGo added support for WASI reactors (it should!), then it would look something like this:
So, my comment regarding Does it make sense? |
The only thing unclear to me is that calling But yeah, your comment finally totally makes sense to me, and I will work on reactor support in TinyGo in order to make TinyGo more WASI spec compatible. Thanks for the clarification! |
Ah - one more thing: maybe we would call WASI commands would look like
WASI reactors would be like
and then this PR would have no affect on TinyGo. This is kind of a design decision in TinyGo so I am not sure how this would look like when the WASI reactor support lands. |
I don't think it's defined anywhere, WASI spec might have even more tribal knowledge than Proxy-Wasm spec :) But if you look at Emscripten implementation, this is crt1 for WASI command:
and this is crt1 for WASI reactor:
No, no, no! WASI reactors have multiple entrypoints, but none is called as part of initialization (that's the whole difference between commands and reactors), so we don't want to call What we do in this PR is that we call
This PR doesn't affect TinyGo at this point. Currently, TinyGo creates WASI command (using If TinyGo adds support for WASI reactors (using |
OK, finally everything looks clear to me, and thanks for bearing with me. (And I am now thinking that I should have depended on |
WASI reactors differ from WASI commands in that they have multiple
entrypoints (i.e. proxy_on_* callbacks) instead of only main().
Currently, each Proxy-Wasm SDK uses different approch to startup:
AssemblyScript SDK uses Wasm's start function.
C++ SDK creates WASI reactor with global C++ constructors taking
care of early initialization and registration of plugins.
Rust SDK creates Wasm library, and suggests (via examples) using
_start() function called at startup to do early initialization.
Unfortunately, this is the same function name that WASI commands
are using, which means that WASI constructors cannot be injected
and executed at startup.
TinyGo SDK creates WASI command and calls main() at startup, but
it doesn't exit after main() function returns.
Calling main() in WASI reactors would allow us to prepare for when
they are stablized in Rust, and to have a non-breaking fallback in
case TinyGo decides to exit after main() function returns.
Signed-off-by: Piotr Sikora [email protected]