From 496ef9ed693f8395e53c9581aa8e22d78d7161cd Mon Sep 17 00:00:00 2001 From: Xiliang Chen Date: Wed, 22 May 2024 17:08:17 +1200 Subject: [PATCH] basic setup (#20) --- Cargo.lock | 79 ++++++++++-------------------- Cargo.toml | 30 ++++++++++-- Makefile | 3 +- rust-toolchain.toml | 2 + xcq-api/Cargo.toml | 12 ++++- xcq-api/src/lib.rs | 2 + xcq-executor/Cargo.toml | 12 ++++- xcq-executor/src/lib.rs | 2 + xcq-extension-core/Cargo.toml | 12 ++++- xcq-extension-core/src/lib.rs | 2 + xcq-extension-fungibles/Cargo.toml | 12 ++++- xcq-extension-fungibles/src/lib.rs | 2 + xcq-extension/Cargo.toml | 12 ++++- xcq-extension/src/lib.rs | 2 + xcq-primitives/Cargo.toml | 16 ++++++ xcq-primitives/src/lib.rs | 16 ++++++ xcq-runtime-api/Cargo.toml | 18 ++++++- xcq-runtime-api/src/lib.rs | 19 ++++--- xcq-test-runner/Cargo.toml | 8 ++- xcq-types/Cargo.toml | 12 ++++- xcq-types/src/lib.rs | 2 + 21 files changed, 190 insertions(+), 85 deletions(-) create mode 100644 rust-toolchain.toml create mode 100644 xcq-primitives/Cargo.toml create mode 100644 xcq-primitives/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 2338a7f..78c06a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1338,7 +1338,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b482a1d18fa63aed1ff3fe3fcfb3bc23d92cb3903d6b9774f75dc2c4e1001c3a" dependencies = [ "frame-support-procedural-tools-derive", - "proc-macro-crate 3.1.0", + "proc-macro-crate", "proc-macro2", "quote", "syn 2.0.60", @@ -2322,9 +2322,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "3.6.9" +version = "3.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881331e34fa842a2fb61cc2db9643a8fedc615e47cfcc52597d1af0db9a7e8fe" +checksum = "306800abfa29c7f16596b5970a588435e3d5b3149683d00c12b699cc19f895ee" dependencies = [ "arrayvec", "bitvec", @@ -2337,11 +2337,11 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.6.9" +version = "3.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be30eaf4b0a9fba5336683b38de57bb86d179a35862ba6bfcf57625d006bde5b" +checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" dependencies = [ - "proc-macro-crate 2.0.0", + "proc-macro-crate", "proc-macro2", "quote", "syn 1.0.109", @@ -2653,25 +2653,6 @@ dependencies = [ "uint", ] -[[package]] -name = "proc-macro-crate" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" -dependencies = [ - "once_cell", - "toml_edit 0.19.15", -] - -[[package]] -name = "proc-macro-crate" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" -dependencies = [ - "toml_edit 0.20.7", -] - [[package]] name = "proc-macro-crate" version = "3.1.0" @@ -2982,9 +2963,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.11.2" +version = "2.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c453e59a955f81fb62ee5d596b450383d699f152d350e9d23a0db2adb78e4c0" +checksum = "eca070c12893629e2cc820a9761bedf6ce1dcddc9852984d1dc734b8bd9bd024" dependencies = [ "bitvec", "cfg-if", @@ -2996,11 +2977,11 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.11.2" +version = "2.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18cf6c6447f813ef19eb450e985bcce6705f9ce7660db221b59093d15c79c4b7" +checksum = "2d35494501194174bda522a32605929eefc9ecf7e0a326c26db1fdd85881eb62" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 1.0.109", @@ -3298,7 +3279,7 @@ dependencies = [ "Inflector", "blake2", "expander", - "proc-macro-crate 3.1.0", + "proc-macro-crate", "proc-macro2", "quote", "syn 2.0.60", @@ -3653,7 +3634,7 @@ checksum = "0195f32c628fee3ce1dfbbf2e7e52a30ea85f3589da9fe62a8b816d70fc06294" dependencies = [ "Inflector", "expander", - "proc-macro-crate 3.1.0", + "proc-macro-crate", "proc-macro2", "quote", "syn 2.0.60", @@ -4101,28 +4082,6 @@ dependencies = [ "serde", ] -[[package]] -name = "toml_edit" -version = "0.19.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" -dependencies = [ - "indexmap 2.2.6", - "toml_datetime", - "winnow 0.5.40", -] - -[[package]] -name = "toml_edit" -version = "0.20.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" -dependencies = [ - "indexmap 2.2.6", - "toml_datetime", - "winnow 0.5.40", -] - [[package]] name = "toml_edit" version = "0.21.1" @@ -4920,9 +4879,21 @@ version = "0.1.0" name = "xcq-extension-fungibles" version = "0.1.0" +[[package]] +name = "xcq-primitives" +version = "0.1.0" +dependencies = [ + "parity-scale-codec", + "scale-info", +] + [[package]] name = "xcq-runtime-api" version = "0.1.0" +dependencies = [ + "sp-api", + "xcq-primitives", +] [[package]] name = "xcq-test-runner" diff --git a/Cargo.toml b/Cargo.toml index 3c91bce..29e9937 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,17 +1,27 @@ +[workspace.package] +authors = ["Acala Developers "] +edition = "2021" +repository = "https://github.com/open-web3-stack/XCQ" +license = "Apache-2.0" +version = "0.1.0" + [workspace] resolver = "2" members = [ "poc/host", "poc/runtime", "poc/executor", - "xcq-executor", + "xcq-api", - "xcq-extension", + "xcq-executor", "xcq-extension-core", "xcq-extension-fungibles", + "xcq-extension", + "xcq-primitives", "xcq-runtime-api", - "xcq-types", "xcq-test-runner", + "xcq-types", + "examples/example-fungibles", "examples/example-helloworld", ] @@ -23,6 +33,20 @@ panic = "unwind" opt-level = 3 [workspace.dependencies] +xcq-api = { path = "xcq-api", default-features = false } +xcq-executor = { path = "xcq-executor", default-features = false } +xcq-extension-core = { path = "xcq-extension-core", default-features = false } +xcq-extension-fungibles = { path = "xcq-extension-fungibles", default-features = false } +xcq-extension = { path = "xcq-extension", default-features = false } +xcq-primitives = { path = "xcq-primitives", default-features = false } +xcq-runtime-api = { path = "xcq-runtime-api", default-features = false } +xcq-test-runner = { path = "xcq-test-runner", default-features = false } +xcq-types = { path = "xcq-types", default-features = false } + env_logger = { version = "0.11.3" } +parity-scale-codec = { version = "3.6.12", default-features = false } +scale-info = { version = "2.11.3", default-features = false } polkavm = { path = "vendor/polkavm/crates/polkavm", default-features = false } + +sp-api = { version = "29.0.0", default-features = false } diff --git a/Makefile b/Makefile index 718aac0..704f50e 100644 --- a/Makefile +++ b/Makefile @@ -17,12 +17,11 @@ fmt: cargo fmt --all -- --check check: - cargo check --no-default-features --target=wasm32-unknown-unknown -p poc-executor + SKIP_WASM_BUILD= cargo check --no-default-features --target=wasm32-unknown-unknown SKIP_WASM_BUILD= cargo check cd poc/guest; cargo check clippy: - cargo clippy --no-default-features --target=wasm32-unknown-unknown -p poc-executor SKIP_WASM_BUILD= cargo clippy -- -D warnings cd poc/guest; cargo clippy diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..5198580 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.78.0" diff --git a/xcq-api/Cargo.toml b/xcq-api/Cargo.toml index 72d9dff..31bf03f 100644 --- a/xcq-api/Cargo.toml +++ b/xcq-api/Cargo.toml @@ -1,6 +1,14 @@ [package] name = "xcq-api" -version = "0.1.0" -edition = "2021" +description = "API between XCQ host and guest program" +authors.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +version.workspace = true [dependencies] + +[features] +default = ["std"] +std = [] diff --git a/xcq-api/src/lib.rs b/xcq-api/src/lib.rs index 7d12d9a..58456cf 100644 --- a/xcq-api/src/lib.rs +++ b/xcq-api/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(not(feature = "std"), no_std)] + pub fn add(left: usize, right: usize) -> usize { left + right } diff --git a/xcq-executor/Cargo.toml b/xcq-executor/Cargo.toml index 48cf8fc..aa3cb2a 100644 --- a/xcq-executor/Cargo.toml +++ b/xcq-executor/Cargo.toml @@ -1,6 +1,14 @@ [package] name = "xcq-executor" -version = "0.1.0" -edition = "2021" +description = "XCQ program executor" +authors.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +version.workspace = true [dependencies] + +[features] +default = ["std"] +std = [] diff --git a/xcq-executor/src/lib.rs b/xcq-executor/src/lib.rs index 7d12d9a..58456cf 100644 --- a/xcq-executor/src/lib.rs +++ b/xcq-executor/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(not(feature = "std"), no_std)] + pub fn add(left: usize, right: usize) -> usize { left + right } diff --git a/xcq-extension-core/Cargo.toml b/xcq-extension-core/Cargo.toml index 37ca1a5..a77a6b1 100644 --- a/xcq-extension-core/Cargo.toml +++ b/xcq-extension-core/Cargo.toml @@ -1,6 +1,14 @@ [package] name = "xcq-extension-core" -version = "0.1.0" -edition = "2021" +description = "Core extension for XCQ" +authors.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +version.workspace = true [dependencies] + +[features] +default = ["std"] +std = [] diff --git a/xcq-extension-core/src/lib.rs b/xcq-extension-core/src/lib.rs index 7d12d9a..58456cf 100644 --- a/xcq-extension-core/src/lib.rs +++ b/xcq-extension-core/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(not(feature = "std"), no_std)] + pub fn add(left: usize, right: usize) -> usize { left + right } diff --git a/xcq-extension-fungibles/Cargo.toml b/xcq-extension-fungibles/Cargo.toml index 8b692cc..202173c 100644 --- a/xcq-extension-fungibles/Cargo.toml +++ b/xcq-extension-fungibles/Cargo.toml @@ -1,6 +1,14 @@ [package] name = "xcq-extension-fungibles" -version = "0.1.0" -edition = "2021" +description = "Fungibles extension for XCQ" +authors.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +version.workspace = true [dependencies] + +[features] +default = ["std"] +std = [] diff --git a/xcq-extension-fungibles/src/lib.rs b/xcq-extension-fungibles/src/lib.rs index 7d12d9a..58456cf 100644 --- a/xcq-extension-fungibles/src/lib.rs +++ b/xcq-extension-fungibles/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(not(feature = "std"), no_std)] + pub fn add(left: usize, right: usize) -> usize { left + right } diff --git a/xcq-extension/Cargo.toml b/xcq-extension/Cargo.toml index dbb88a2..0c1f1f6 100644 --- a/xcq-extension/Cargo.toml +++ b/xcq-extension/Cargo.toml @@ -1,6 +1,14 @@ [package] name = "xcq-extension" -version = "0.1.0" -edition = "2021" +description = "Extension system for XCQ" +authors.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +version.workspace = true [dependencies] + +[features] +default = ["std"] +std = [] diff --git a/xcq-extension/src/lib.rs b/xcq-extension/src/lib.rs index 7d12d9a..58456cf 100644 --- a/xcq-extension/src/lib.rs +++ b/xcq-extension/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(not(feature = "std"), no_std)] + pub fn add(left: usize, right: usize) -> usize { left + right } diff --git a/xcq-primitives/Cargo.toml b/xcq-primitives/Cargo.toml new file mode 100644 index 0000000..30dcc40 --- /dev/null +++ b/xcq-primitives/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "xcq-primitives" +description = "Primitives for XCQ" +authors.workspace = true +edition.workspace = true +repository.workspace = true +license.workspace = true +version.workspace = true + +[dependencies] +parity-scale-codec = { workspace = true } +scale-info = { workspace = true } + +[features] +default = ["std"] +std = ["parity-scale-codec/std", "scale-info/std"] diff --git a/xcq-primitives/src/lib.rs b/xcq-primitives/src/lib.rs new file mode 100644 index 0000000..f0fa12d --- /dev/null +++ b/xcq-primitives/src/lib.rs @@ -0,0 +1,16 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; + +use alloc::{string::String, vec::Vec}; +use parity_scale_codec::{Decode, Encode}; +use scale_info::TypeInfo; + +pub type XcqResponse = Vec; + +#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, TypeInfo)] +pub enum XcqError { + Custom(String), +} + +pub type XcqResult = Result; diff --git a/xcq-runtime-api/Cargo.toml b/xcq-runtime-api/Cargo.toml index 08317ad..c52d768 100644 --- a/xcq-runtime-api/Cargo.toml +++ b/xcq-runtime-api/Cargo.toml @@ -1,6 +1,20 @@ [package] name = "xcq-runtime-api" -version = "0.1.0" -edition = "2021" +description = "Runtime API for XCQ" +authors.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +version.workspace = true [dependencies] +xcq-primitives = { workspace = true } + +sp-api = { workspace = true } + +[features] +default = ["std"] +std = [ + "xcq-primitives/std", + "sp-api/std", +] diff --git a/xcq-runtime-api/src/lib.rs b/xcq-runtime-api/src/lib.rs index 7d12d9a..434d913 100644 --- a/xcq-runtime-api/src/lib.rs +++ b/xcq-runtime-api/src/lib.rs @@ -1,14 +1,13 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right -} +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; -#[cfg(test)] -mod tests { - use super::*; +use alloc::vec::Vec; +use sp_api::decl_runtime_apis; +use xcq_primitives::XcqResult; - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); +decl_runtime_apis! { + pub trait XcqApi { + fn execute_query(query: Vec, input: Vec) -> XcqResult; } } diff --git a/xcq-test-runner/Cargo.toml b/xcq-test-runner/Cargo.toml index dd67494..dad732f 100644 --- a/xcq-test-runner/Cargo.toml +++ b/xcq-test-runner/Cargo.toml @@ -1,6 +1,10 @@ [package] name = "xcq-test-runner" -version = "0.1.0" -edition = "2021" +description = "XCQ program runner. Only for testing purpose." +authors.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +version.workspace = true [dependencies] diff --git a/xcq-types/Cargo.toml b/xcq-types/Cargo.toml index dd5bc03..75b312a 100644 --- a/xcq-types/Cargo.toml +++ b/xcq-types/Cargo.toml @@ -1,6 +1,14 @@ [package] name = "xcq-types" -version = "0.1.0" -edition = "2021" +description = "Metatype system for XCQ" +authors.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +version.workspace = true [dependencies] + +[features] +default = ["std"] +std = [] diff --git a/xcq-types/src/lib.rs b/xcq-types/src/lib.rs index 7d12d9a..58456cf 100644 --- a/xcq-types/src/lib.rs +++ b/xcq-types/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(not(feature = "std"), no_std)] + pub fn add(left: usize, right: usize) -> usize { left + right }