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

Reimplement wasmtime-wasi on top of wasmtime #899

Merged

Conversation

alexcrichton
Copy link
Member

This commit reimplements the wasmtime-wasi crate on top of the
wasmtime API crate, instead of being placed on top of the wasmtime-*
family of internal crates. The purpose here is to continue to exercise
the API as well as avoid usage of internals wherever possible and
instead use the safe API as much as possible.

The wasmtime-wasi crate's API has been updated as part of this PR as
well. The general outline of it is now:

  • Each module snapshot has a WasiCtxBuilder, WasiCtx, and Wasi
    type.
    • The WasiCtx* types are reexported from wasi-common.
    • The Wasi type is synthesized by the wig crate's procedural macro
  • The Wasi type exposes one constructor which takes a Store and a
    WasiCtx, and produces a Wasi
  • Each Wasi struct fields for all the exported functions in that wasi
    module. They're all public an they all have type wasmtime::Func
  • The Wasi type has a get_export method to fetch an struct field by
    name.

The intention here is that we can continue to make progress on #727 by
integrating WASI construction into the Instance::new experience, but
it requires everything to be part of the same system!

The main oddity required by the wasmtime-wasi crate is that it needs
access to the caller's memory export, if any. This is currently done
with a bit of a hack and is expected to go away once interface types are
more fully baked in.

This commit reimplements the `wasmtime-wasi` crate on top of the
`wasmtime` API crate, instead of being placed on top of the `wasmtime-*`
family of internal crates. The purpose here is to continue to exercise
the API as well as avoid usage of internals wherever possible and
instead use the safe API as much as possible.

The `wasmtime-wasi` crate's API has been updated as part of this PR as
well. The general outline of it is now:

* Each module snapshot has a `WasiCtxBuilder`, `WasiCtx`, and `Wasi`
  type.
  * The `WasiCtx*` types are reexported from `wasi-common`.
  * The `Wasi` type is synthesized by the `wig` crate's procedural macro
* The `Wasi` type exposes one constructor which takes a `Store` and a
  `WasiCtx`, and produces a `Wasi`
* Each `Wasi` struct fields for all the exported functions in that wasi
  module. They're all public an they all have type `wasmtime::Func`
* The `Wasi` type has a `get_export` method to fetch an struct field by
  name.

The intention here is that we can continue to make progress on bytecodealliance#727 by
integrating WASI construction into the `Instance::new` experience, but
it requires everything to be part of the same system!

The main oddity required by the `wasmtime-wasi` crate is that it needs
access to the caller's `memory` export, if any. This is currently done
with a bit of a hack and is expected to go away once interface types are
more fully baked in.
Copy link
Member

@peterhuene peterhuene left a comment

Choose a reason for hiding this comment

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

This looks great 👍 ! Just a few nit review comments.

crates/api/src/func.rs Outdated Show resolved Hide resolved
crates/wasi/src/old/snapshot_0.rs Show resolved Hide resolved
crates/wasi-common/wig/src/wasi.rs Show resolved Hide resolved
@alexcrichton alexcrichton merged commit 3dd5a3c into bytecodealliance:master Feb 6, 2020
@alexcrichton alexcrichton deleted the wasi-no-internals branch February 6, 2020 15:23
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.

None yet

2 participants