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

feat: Wasm module implementation #73

Merged
merged 29 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9ca9868
add a draft Module loader functionalit
Mr-Leshiy Jan 30, 2024
530377c
Merge branch 'main' into feat/wasm-module-loader
Mr-Leshiy Jan 30, 2024
6bc9f5b
remove rust-toolchain cargo config value
Mr-Leshiy Jan 30, 2024
e6e4119
fix scoping
Mr-Leshiy Jan 30, 2024
29a3fd9
update Error handling, update checks
Mr-Leshiy Jan 30, 2024
a19aa75
add Clone derive
Mr-Leshiy Jan 30, 2024
850c18d
fix some lints
Mr-Leshiy Jan 30, 2024
7938661
update
Mr-Leshiy Jan 30, 2024
e647211
add engine docs
Mr-Leshiy Jan 30, 2024
1fcc34b
add wasm module docs
Mr-Leshiy Jan 30, 2024
f1eba16
fix spell check
Mr-Leshiy Jan 30, 2024
c90355d
fix deny failure
Mr-Leshiy Jan 31, 2024
ddabd0d
update module
Mr-Leshiy Feb 1, 2024
fdb820d
wip
Mr-Leshiy Feb 1, 2024
342a3a2
update store management
Mr-Leshiy Feb 1, 2024
f472304
add more docs
Mr-Leshiy Feb 1, 2024
223dbdc
add Context struct, remove engine mod
Mr-Leshiy Feb 1, 2024
85b2dcb
wip
Mr-Leshiy Feb 1, 2024
6f662cd
fix checks
Mr-Leshiy Feb 1, 2024
288f9a7
update Cargo.toml file
Mr-Leshiy Feb 1, 2024
0adf84a
fix build
Mr-Leshiy Feb 1, 2024
5cd4ac7
fix build
Mr-Leshiy Feb 1, 2024
b8a170d
Merge branch 'main' into feat/wasm-module-loader
Mr-Leshiy Feb 1, 2024
28f2763
Update hermes/bin/src/wasm/module.rs
Mr-Leshiy Feb 1, 2024
d9e5289
fix suggestions
Mr-Leshiy Feb 2, 2024
13363a6
add docs
Mr-Leshiy Feb 2, 2024
9f8fc0c
Merge branch 'main' into feat/wasm-module-loader
Mr-Leshiy Feb 2, 2024
b3e9d56
Update hermes/bin/src/main.rs
Mr-Leshiy Feb 2, 2024
589d79a
cleanup
Mr-Leshiy Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .config/dictionaries/project.dic
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ vitss
voteplan
voteplans
WASI
wasmtime
webasm
yoroi
4 changes: 3 additions & 1 deletion hermes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ version = "0.0.1"
authors = [
"Steven Johnson <steven.johnson@iohk.io>"
]
rust-version = "1.73"
homepage = "https://input-output-hk.github.io/hermes"
repository = "https://github.com/input-output-hk/hermes"
license = "MIT OR Apache-2.0"
Expand Down Expand Up @@ -55,3 +54,6 @@ missing_docs_in_private_items = "deny"
# issue: https://github.com/input-output-hk/hermes/issues/63
pallas = { version = "0.21.0", git = "https://github.com/input-output-hk/catalyst-pallas.git", branch = "feat/hardano-read-blocks-iter-send" }
pallas-hardano = { version = "0.21.0", git = "https://github.com/input-output-hk/catalyst-pallas.git", branch = "feat/hardano-read-blocks-iter-send" }

wasmtime = "16.0.0"
thiserror = "1.0"
4 changes: 4 additions & 0 deletions hermes/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ repository.workspace = true

[lints]
workspace = true

[dependencies]
thiserror = { workspace = true }
wasmtime = { workspace = true, features = ["component-model"] }
2 changes: 2 additions & 0 deletions hermes/bin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
//! Intentionally empty
//! This file exists, so that doc tests can be used inside binary crates.

mod wasm;
43 changes: 43 additions & 0 deletions hermes/bin/src/wasm/engine.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! WASM engine implementation
//! Wrapper over the `wasmtime::Engine` struct with some specific configuration setup.

use std::ops::{Deref, DerefMut};

use wasmtime::{Config as WasmConfig, Engine as WasmEngine};

use super::Error;

/// WASM Engine struct
pub(crate) struct Engine(WasmEngine);

impl Deref for Engine {
type Target = WasmEngine;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for Engine {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl Engine {
/// Creates a new instance of the `Engine`.
///
/// # Errors
///
/// - `Error::Wasm`. Returns an error if the `WasmEngine` fails to initialize.
#[allow(dead_code)]
pub(crate) fn new() -> Result<Self, Error> {
let mut config = WasmConfig::new();
config.wasm_component_model(true);
config.consume_fuel(false);

let engine = WasmEngine::new(&config)?;

Ok(Self(engine))
}
}
29 changes: 29 additions & 0 deletions hermes/bin/src/wasm/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! WASM related structures and functions.
//! All implementation based on [wasmtime](https://crates.io/crates/wasmtime) crate dependency.

mod engine;
mod module;

/// WASM module errors.
#[derive(thiserror::Error, Debug)]
enum Error {
/// Exports mismatch
#[error("Exports mismatch")]
ExportsMismatch,

/// Imports mismatch
#[error("Imports mismatch")]
ImportsMismatch,

/// Export module entity is not a function
#[error("Export module entity is not a function, name: {0}")]
ExportNotAFunc(String),

/// Import module entity is not a function
#[error("Import module entity is not a function, module: {0}, name: {1}")]
ImportNotAFunc(String, String),

/// Internal wasmtime errors
#[error(transparent)]
Wasm(#[from] wasmtime::Error),
}