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

Import only necessary WASI APIs #1146

Closed
nullpo-head opened this issue Mar 2, 2022 · 0 comments · Fixed by #1272
Closed

Import only necessary WASI APIs #1146

nullpo-head opened this issue Mar 2, 2022 · 0 comments · Fixed by #1272

Comments

@nullpo-head
Copy link

Currently, Grain seems to emit a wasm binary that imports almost all WASI APIs, regardless of whether they are actually used or not. This means that on a WASM runtime that does not support all WASI APIs, the Grain app will not run, even if the Grain app is actually calling only the WASI APIs supported by that runtime.

Is it possible to improve Grain so that it imports only the APIs that are actually used, instead of always importing all WASI APIs?

I'd also like to note that WASI is making big changes on its API12, so reducing imports will also benefit future compatibility.

For example,

import Process from "sys/process"
Process.exit(1)

This code only calls the proc_exit WASI API through Grain's standard library, but the emitted wasm module imports almost all WASI APIs.

  (import "wasi_snapshot_preview1" "fd_write" (func (;0;) (type 2)))
  (import "wasi_snapshot_preview1" "args_get" (func (;1;) (type 0)))
  (import "wasi_snapshot_preview1" "args_sizes_get" (func (;2;) (type 0)))
-- snip --
  (import "wasi_snapshot_preview1" "path_rename" (func (;36;) (type 11)))

Footnotes

  1. FS APIs will have big changes https://github.com/WebAssembly/WASI/issues/469#issuecomment-1045251844

  2. Some APIs will be removed, such as proc_raise, which Grain always imports. https://github.com/WebAssembly/WASI/issues/26

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 a pull request may close this issue.

1 participant