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(runtime-interface): split sandbox interface out of runtime-interface #4034

Merged
merged 10 commits into from
Jul 5, 2024
Merged
16 changes: 13 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ members = [
"node/testing",
"pallets/*",
"runtime/*",
"runtime-interface/sandbox",
"utils/*",
"utils/runtime-fuzzer/fuzz"
]
Expand Down Expand Up @@ -229,6 +230,7 @@ gear-lazy-pages-native-interface = { path = "lazy-pages/native-interface" }
gear-node-testing = { path = "node/testing" }
gear-runtime-common = { path = "runtime/common", default-features = false }
gear-runtime-interface = { path = "runtime-interface", default-features = false }
gear-sandbox-interface = { path = "runtime-interface/sandbox", default-features = false }
gear-runtime-primitives = { path = "runtime/primitives", default-features = false }
gear-sandbox = { path = "sandbox/sandbox", default-features = false }
gear-sandbox-env = { path = "sandbox/env", default-features = false }
Expand Down
8 changes: 3 additions & 5 deletions runtime-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ repository.workspace = true
gear-core.workspace = true
gear-lazy-pages-common.workspace = true
gear-lazy-pages = { workspace = true, optional = true }
gear-sandbox-host = { workspace = true, optional = true }
gear-sandbox-interface.workspace = true

sp-io.workspace = true
sp-runtime-interface.workspace = true
sp-runtime-interface = { workspace = true, default-features = false }
sp-std.workspace = true
sp-wasm-interface.workspace = true

byteorder.workspace = true
codec = { workspace = true }
Expand All @@ -38,12 +37,11 @@ default = ["std"]
std = [
"gear-core/std",
"gear-lazy-pages",
"gear-sandbox-host",
"gear-sandbox-interface/std",

"sp-io/std",
"sp-std/std",
"sp-runtime-interface/std",
"sp-wasm-interface/std",

"byteorder/std",
"codec/std",
Expand Down
28 changes: 28 additions & 0 deletions runtime-interface/sandbox/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "gear-sandbox-interface"
version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true

[dependencies]
sp-runtime-interface.workspace = true
sp-wasm-interface.workspace = true

codec = { workspace = true }
gear-sandbox-host = { workspace = true, optional = true }
log = { workspace = true, optional = true }

[features]
default = ["std"]
std = [
"gear-sandbox-host",

"codec/std",
"log",

"sp-runtime-interface/std",
"sp-wasm-interface/std",
]
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

//! Runtime interface for gear node

#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "std")]
use gear_sandbox_host::sandbox::env::Instantiate;
use sp_runtime_interface::{runtime_interface, Pointer};
Expand Down
6 changes: 2 additions & 4 deletions runtime-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ use {
gear_lazy_pages::LazyPagesStorage,
};

mod gear_sandbox;

#[cfg(feature = "std")]
pub use gear_sandbox::init as sandbox_init;
pub use gear_sandbox::sandbox;
pub use gear_sandbox_interface::init as sandbox_init;
pub use gear_sandbox_interface::sandbox;

const _: () = assert!(core::mem::size_of::<HostPointer>() >= core::mem::size_of::<usize>());

Expand Down
4 changes: 2 additions & 2 deletions sandbox/sandbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ wasmi = { git = "https://github.com/gear-tech/wasmi", branch = "gear-v0.30.0", d
sp-core.workspace = true
sp-std.workspace = true
sp-wasm-interface-common.workspace = true
gear-runtime-interface.workspace = true
gear-sandbox-interface.workspace = true
gear-sandbox-env.workspace = true

[dev-dependencies]
Expand All @@ -35,7 +35,7 @@ std = [
"sp-core/std",
"sp-std/std",
"sp-wasm-interface-common/std",
"gear-runtime-interface/std",
"gear-sandbox-interface/std",
"gear-sandbox-env/std",
"wasmi/std",
"wasmi/virtual_memory",
Expand Down
2 changes: 1 addition & 1 deletion sandbox/sandbox/src/host_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use crate::{
env, AsContextExt, Error, GlobalsSetError, HostFuncType, ReturnValue, SandboxStore, Value,
};
use alloc::string::String;
use gear_runtime_interface::sandbox;
use gear_sandbox_env::WasmReturnValue;
use gear_sandbox_interface::sandbox;
use sp_core::RuntimeDebug;
use sp_std::{marker, mem, prelude::*, rc::Rc, slice, vec};
use sp_wasm_interface_common::HostPointer;
Expand Down
37 changes: 19 additions & 18 deletions utils/crates-io/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ pub fn patch(pkg: &Package) -> Result<Manifest> {

match manifest.name.as_str() {
"gear-core-processor" => core_processor::patch(doc),
"gear-runtime-interface" => runtime_interface::patch(doc),
"gear-sandbox" => sandbox::patch(doc),
"gear-sandbox-host" => sandbox_host::patch(doc),
"gear-sandbox-interface" => sandbox_interface::patch(doc),
"gmeta" => gmeta::patch(doc),
"gmeta-codegen" => gmeta_codegen::patch(doc),
_ => {}
Expand Down Expand Up @@ -145,7 +145,24 @@ mod gmeta_codegen {
}
}

mod runtime_interface {
/// sandbox handler.
mod sandbox {
use toml_edit::DocumentMut;

/// Replace the wasmi module to the crates-io version.
pub fn patch(manifest: &mut DocumentMut) {
let Some(wasmi) = manifest["dependencies"]["wasmi"].as_inline_table_mut() else {
return;
};
wasmi.insert("package", "gwasmi".into());
wasmi.insert("version", "0.30.0".into());
wasmi.remove("branch");
wasmi.remove("git");
}
}

/// sandbox interface handler
mod sandbox_interface {
use super::GP_RUNTIME_INTERFACE_VERSION;
use toml_edit::DocumentMut;

Expand All @@ -164,22 +181,6 @@ mod runtime_interface {
}
}

/// sandbox handler.
mod sandbox {
use toml_edit::DocumentMut;

/// Replace the wasmi module to the crates-io version.
pub fn patch(manifest: &mut DocumentMut) {
let Some(wasmi) = manifest["dependencies"]["wasmi"].as_inline_table_mut() else {
return;
};
wasmi.insert("package", "gwasmi".into());
wasmi.insert("version", "0.30.0".into());
wasmi.remove("branch");
wasmi.remove("git");
}
}

/// sandbox_host handler.
mod sandbox_host {
use toml_edit::DocumentMut;
Expand Down
5 changes: 2 additions & 3 deletions utils/crates-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub const SAFE_DEPENDENCIES: [&str; 15] = [
/// NOTE: Each package in this array could possibly depend
/// on the previous one, please be cautious about changing
/// the order.
pub const STACKED_DEPENDENCIES: [&str; 14] = [
pub const STACKED_DEPENDENCIES: [&str; 13] = [
"gcore",
"gmeta",
"gear-core",
Expand All @@ -61,8 +61,7 @@ pub const STACKED_DEPENDENCIES: [&str; 14] = [
"gear-sandbox-host",
"gear-lazy-pages-common",
"gear-lazy-pages",
"gear-runtime-interface",
"gear-lazy-pages-interface",
"gear-sandbox-interface",
"gear-sandbox",
"gear-core-backend",
"gear-core-processor",
Expand Down
Loading