Skip to content
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

feat: WASI support for browser runtime #196

Merged
merged 4 commits into from
Jan 4, 2023
Merged

Conversation

bhelx
Copy link
Contributor

@bhelx bhelx commented Jan 3, 2023

closes #160

Goal is not to expose all the WASI functionality, but to just write minimum code to allow PDK targets that require WASI (e.g. tinygo compiled plugins) to work in the browser. We can follow up with allowing the user more control over the WASI environment.

nilslice
nilslice previously approved these changes Jan 3, 2023
@nilslice
Copy link
Member

nilslice commented Jan 3, 2023

Oh, these also may need to be executed if they exist:

enum Runtime {

@sunfishcode
Copy link

Oh, these also may need to be executed if they exist:

enum Runtime {

Any program meant to be run in a WASI environment shouldn't be expecting additional initialization calls beyond _start.

@zshipko
Copy link
Contributor

zshipko commented Jan 3, 2023

Any program meant to be run in a WASI environment shouldn't be expecting additional initialization calls beyond _start.

Those calls are being done instead of _start. We found that when compiling Haskell to WASM you're able to export multiple functions and initializing with hs_init allows for those functions to be called directly. Is side-stepping the _start function like that an issue?

@@ -82,6 +82,9 @@ export default class ExtismPlugin {
env: environment
};
this.module = await WebAssembly.instantiate(this.moduleData, env);
if (this.module.instance.exports._start) {
wasi.start(this.module.instance);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to call _start here, since that will actually run the plugin, it should be called in Plugin.call instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zshipko so, you mean it should adopt the same methodology we use in the Rust runtime?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i don't think it should ever automatically be called, the user should call it themselves (that's how it's handled in the Rust runtime)

also, after _start is called the module should be reinstantiated before any function can be called again.

@bhelx bhelx merged commit 908edf2 into main Jan 4, 2023
@bhelx bhelx deleted the wasi-support-in-browser-runtime branch January 4, 2023 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WASI support in the browser runtime
4 participants