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

refactor(smartengine): add a layer of indirection to support alternative wasm runtimes #3151

Closed
wants to merge 5 commits into from

Conversation

xxchan
Copy link
Contributor

@xxchan xxchan commented Apr 15, 2023

Context of this PR: I'm working on integrating WasmEdge as an alternative runtime for Fluvio smartengine. (WasmEdge/WasmEdge#2231)

Currently, the code of smartengine is highly coupled with Wasmtime, so it would be a little bit hard (or dirty) to support alternative wasm engines. This PR improves the situation in 2 ways:

  1. There are some reusable code not coupled with the engine. So I extracted them into a new module config.
  2. The public APIs of the smartengine crate, which are depended on by other crates, aren't very clear. So I reorganized it: Public structs are defined in engine/mod.rs. The implementation details are represented as an inner field, and can be imported according to which feature is enabled. This style is learned from backtrace-rs and getrandom (e.g., https://github.com/rust-lang/backtrace-rs/blob/b3e5bb857773fcc6fc8247374264bd4c8acd5387/src/backtrace/mod.rs)

P.S. here's the WIP work of WasmEdge support xxchan#1. It's almost finished. But I think splitting it into smaller ones would be easier to review, and get quicker feedback. Besides, I think the refactoring is generally trivial, and makes some sense whether or not WasmEdge is accepted as a new engine, so I submitted this PR first :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is extracted from engine.rs without any change.

Comment on lines 1 to 6
cfg_if::cfg_if! {
if #[cfg(feature = "engine")] {
pub(crate) mod memory;
pub(crate) mod transforms;
pub(crate) mod init;
pub(crate) mod error;
pub mod metrics;
mod engine;
mod state;
pub use engine::*;
pub mod instance;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new engine mod will correspond to the feature engine. The implementations are moved to engine::wasmtime_engine.

@xxchan
Copy link
Contributor Author

xxchan commented Apr 15, 2023

@sehz PTAL. Thanks 🙏

Comment on lines 15 to 19
engine = ["wasmtime"]
engine = ["wasmtime-engine"]
wasi = ["wasmtime-wasi", "engine"]
transformation = ["serde_json", "serde_yaml"]
default = ["engine"]

wasmtime-engine = ["wasmtime", "wasmtime-wasi"]
Copy link
Contributor

Choose a reason for hiding this comment

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

with this update, wasmtime-wasi dependency will be pulled by default, could you update it to keep current behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, this should be a mistake.

@sehz sehz added this to the 0.10.8 milestone Apr 15, 2023
@sehz
Copy link
Contributor

sehz commented Apr 15, 2023

Thanks for the work. It's still bit large. What I suggest is to split this into separate PR:
(1) re-org without changing semantics.
(2) WASI related changes

@xxchan
Copy link
Contributor Author

xxchan commented Apr 15, 2023

@sehz I think the semantic is not changed. But I've created a new PR #3152 without the changes of Cargo features and the "imp" style, if this is what you mean.

@xxchan xxchan changed the title refactor: improve modularity of smartengine refactor(smartengine): add a layer of indirection to support alternative wasm runtimes Apr 15, 2023
@xxchan xxchan marked this pull request as draft April 15, 2023 20:32
bors bot pushed a commit that referenced this pull request Apr 17, 2023
This PR is part of #3151 (see more context there), containing only trivial code reorganizations, without any actual changes.

To summarize:
- a new `engine` mod, corresponding to the feature `engine`. The implementations are moved to `engine::wasmtime_engine`.
- There are some reusable code not coupled with the engine. So I extracted them into a new module `config`.
@sehz sehz modified the milestones: 0.10.8, 0.10.9 May 1, 2023
@sehz sehz modified the milestones: 0.10.9, 0.10.10 May 13, 2023
@sehz sehz removed this from the 0.10.10 milestone Jun 2, 2023
@xxchan xxchan closed this Jul 31, 2023
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.

3 participants