diff --git a/Cargo.lock b/Cargo.lock index d07b7e35d26..b9b062af6a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4789,14 +4789,13 @@ dependencies = [ "gear-core", "gear-lazy-pages", "gear-lazy-pages-common", - "gear-sandbox-host", + "gear-sandbox-interface", "log", "parity-scale-codec", "sha2 0.10.8", "sp-io", "sp-runtime-interface", "sp-std 8.0.0 (git+https://github.com/gear-tech/polkadot-sdk.git?branch=gear-v1.3.0)", - "sp-wasm-interface", "winapi", ] @@ -4813,8 +4812,8 @@ name = "gear-sandbox" version = "1.4.2" dependencies = [ "assert_matches", - "gear-runtime-interface", "gear-sandbox-env", + "gear-sandbox-interface", "log", "parity-scale-codec", "sp-core", @@ -4853,6 +4852,17 @@ dependencies = [ "wasmi 0.13.2", ] +[[package]] +name = "gear-sandbox-interface" +version = "1.4.2" +dependencies = [ + "gear-sandbox-host", + "log", + "parity-scale-codec", + "sp-runtime-interface", + "sp-wasm-interface", +] + [[package]] name = "gear-service" version = "1.4.2" diff --git a/Cargo.toml b/Cargo.toml index 6bc01f789c4..a261d67604f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -99,6 +99,7 @@ members = [ "node/testing", "pallets/*", "runtime/*", + "runtime-interface/sandbox", "utils/*", "utils/runtime-fuzzer/fuzz" ] @@ -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 } diff --git a/runtime-interface/Cargo.toml b/runtime-interface/Cargo.toml index 45c1e7317dd..f58660e1ac9 100644 --- a/runtime-interface/Cargo.toml +++ b/runtime-interface/Cargo.toml @@ -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 } @@ -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", diff --git a/runtime-interface/sandbox/Cargo.toml b/runtime-interface/sandbox/Cargo.toml new file mode 100644 index 00000000000..9d0e9101031 --- /dev/null +++ b/runtime-interface/sandbox/Cargo.toml @@ -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", +] diff --git a/runtime-interface/src/gear_sandbox/detail.rs b/runtime-interface/sandbox/src/detail.rs similarity index 100% rename from runtime-interface/src/gear_sandbox/detail.rs rename to runtime-interface/sandbox/src/detail.rs diff --git a/runtime-interface/src/gear_sandbox/mod.rs b/runtime-interface/sandbox/src/lib.rs similarity index 99% rename from runtime-interface/src/gear_sandbox/mod.rs rename to runtime-interface/sandbox/src/lib.rs index 4a4148061e7..1779355e4dc 100644 --- a/runtime-interface/src/gear_sandbox/mod.rs +++ b/runtime-interface/sandbox/src/lib.rs @@ -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}; diff --git a/runtime-interface/src/lib.rs b/runtime-interface/src/lib.rs index c1aecb21437..3a638462471 100644 --- a/runtime-interface/src/lib.rs +++ b/runtime-interface/src/lib.rs @@ -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::() >= core::mem::size_of::()); diff --git a/sandbox/sandbox/Cargo.toml b/sandbox/sandbox/Cargo.toml index 4126669f2ec..e58b4199f49 100644 --- a/sandbox/sandbox/Cargo.toml +++ b/sandbox/sandbox/Cargo.toml @@ -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] @@ -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", diff --git a/sandbox/sandbox/src/host_executor.rs b/sandbox/sandbox/src/host_executor.rs index 86dbd2e2a0a..bcb03e01d2b 100644 --- a/sandbox/sandbox/src/host_executor.rs +++ b/sandbox/sandbox/src/host_executor.rs @@ -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; diff --git a/utils/crates-io/src/handler.rs b/utils/crates-io/src/handler.rs index ae2bc69bb0d..c457c86c805 100644 --- a/utils/crates-io/src/handler.rs +++ b/utils/crates-io/src/handler.rs @@ -44,9 +44,9 @@ pub fn patch(pkg: &Package) -> Result { 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), _ => {} @@ -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; @@ -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; diff --git a/utils/crates-io/src/lib.rs b/utils/crates-io/src/lib.rs index feb22708cb2..a869b4e2bae 100644 --- a/utils/crates-io/src/lib.rs +++ b/utils/crates-io/src/lib.rs @@ -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", @@ -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",