wapc-rs icon indicating copy to clipboard operation
wapc-rs copied to clipboard

Introduce async support

Open flavio opened this issue 1 year ago • 3 comments

This is a massive change required to fix https://github.com/wapc/wapc-rs/issues/92

Changes to wapc crate

Allow waPC host to be used inside of an asynchronous runtime

New structs and traits have been added:

  • New struct WapcHostAsync, this is the equivalent of WapcHost but for async environments.
  • New trait WebAssemblyEngineProviderAsync, this is the equivalent of WebAssemblyEngineProvider but for async environments.
  • New trait ModuleHostAsync, this is the equivalent of ModuleHost but for async environments.

An async runtime has an async host callback function. The new type alias HostCallbackAsync is used to define this function. The signature of this function is slightly different from the one of the sync counterpart. All the input paremeters are owned types, not pointers. That's required because the function can be sent to different threads by the async runtime; introducing lifetime constraints proved to be impossible.

The async support is behind a feature flag named asyc. This flag is enabled by default. The implementation relies on the tokio crate.

Other notable changes:

  • The sync code has been moved to dedicated files to separate it from the async code.
  • The documentation now states which feature flags might be required to use a struct, type, trait, or method.

Changes to wasmtime-provider crate

New structs and traits have been added:

  • New struct WasmtimeEngineProviderAsync, this is the equivalent of WasmtimeEngineProvider but for async environments.
  • New struct WasmtimeEngineProviderAsyncPre, this is the equivalent of WasmtimeEngineProviderPre but for async environments.
  • The WasmtimeEngineProviderBuilder has been extened to allow the creation of the new "async" objects describe above.

The async support is behind a feature flag named asyc. This flag is enabled by default. The implementation relies on the tokio crate.

Other notable changes:

  • The sync code has been moved to dedicated files to separate it from the async code.
  • The documentation now states which feature flags might be required to use a struct, type, trait, or method.
  • New and improved tests
  • Reorganized the examples, new ones have been introduced for the async counterparts
  • Improved make test target to cover all the different combination of feature flags
  • Fix compilation errors caused by different flag combinations

flavio avatar Aug 13 '24 14:08 flavio

Once merged, we will have to tag new release of wapc and wasmtime-provider. I wonder if we should do a major release instead of a minor one.

Ideas?

flavio avatar Aug 13 '24 14:08 flavio

Thanks for get awesome description! I agree this probably warrants a new major release. I'm a little busy but I will review this as soon.

pkedy avatar Aug 20 '24 13:08 pkedy

@pkedy, did you have chance to look at the PR? :pray:

flavio avatar Sep 02 '24 16:09 flavio

@pkedy can you please take a look at the PR? :pray:

flavio avatar Sep 20 '24 12:09 flavio

I've rebased the PR against the latest changed that landed into the master branch. I'll merge it once everything is green

flavio avatar Sep 24 '24 06:09 flavio

wasmtime-provider 2.0.0 and wapc 2.0.0 are now available on crates.io 🥳

flavio avatar Sep 24 '24 06:09 flavio