-
Notifications
You must be signed in to change notification settings - Fork 488
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
Conversation
There was a problem hiding this comment.
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.
crates/fluvio-smartengine/src/lib.rs
Outdated
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; | ||
} | ||
} |
There was a problem hiding this comment.
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
.
@sehz PTAL. Thanks 🙏 |
crates/fluvio-smartengine/Cargo.toml
Outdated
engine = ["wasmtime"] | ||
engine = ["wasmtime-engine"] | ||
wasi = ["wasmtime-wasi", "engine"] | ||
transformation = ["serde_json", "serde_yaml"] | ||
default = ["engine"] | ||
|
||
wasmtime-engine = ["wasmtime", "wasmtime-wasi"] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Thanks for the work. It's still bit large. What I suggest is to split this into separate PR: |
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`.
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:
config
.smartengine
crate, which are depended on by other crates, aren't very clear. So I reorganized it: Public structs are defined inengine/mod.rs
. The implementation details are represented as aninner
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 :)