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

Introduce async support #96

Merged
merged 8 commits into from
Sep 24, 2024
Merged

Introduce async support #96

merged 8 commits into from
Sep 24, 2024

Conversation

flavio
Copy link
Member

@flavio flavio commented Aug 13, 2024

This is a massive change required to fix #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 flavio self-assigned this Aug 13, 2024
@flavio flavio added enhancement New feature or request rust Pull requests that update Rust code labels Aug 13, 2024
@flavio flavio requested review from pkedy and jsoverson August 13, 2024 14:22
@flavio
Copy link
Member Author

flavio commented Aug 13, 2024

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?

@pkedy
Copy link
Member

pkedy commented Aug 20, 2024

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.

@flavio
Copy link
Member Author

flavio commented Sep 2, 2024

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

Comment on lines +264 to +265
cfg_if::cfg_if! {
if #[cfg(feature = "wasi")] {
Copy link
Contributor

@muse254 muse254 Sep 20, 2024

Choose a reason for hiding this comment

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

Here we can try

No, makes sense

@flavio
Copy link
Member Author

flavio commented Sep 20, 2024

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

Add `doc` target to the main Makefile. This provides a way to test how
the docs are going to be rendered on docs.rs

Signed-off-by: Flavio Castelli <[email protected]>
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.

Fixes wapc#92

Signed-off-by: Flavio Castelli <[email protected]>
Allow usage of wasmtime-provider inside of an asynchronous runtime.

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

Fixes wapc#92

Signed-off-by: Flavio Castelli <[email protected]>
This is required to simplify the development process

Signed-off-by: Flavio Castelli <[email protected]>
@flavio
Copy link
Member Author

flavio commented Sep 24, 2024

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

This is a major release that adds support for `async` providers

Signed-off-by: Flavio Castelli <[email protected]>
This is the first release of the wasmtime-provider that provides an
async provider for wapc.

Signed-off-by: Flavio Castelli <[email protected]>
Consume latest version of wapc

Signed-off-by: Flavio Castelli <[email protected]>
Consume latest version of wapc

Signed-off-by: Flavio Castelli <[email protected]>
@flavio flavio merged commit db7c363 into wapc:master Sep 24, 2024
3 checks passed
@flavio flavio deleted the async branch September 24, 2024 06:32
@flavio
Copy link
Member Author

flavio commented Sep 24, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WapcHost usage in async contexts
3 participants