Skip to content

Commit

Permalink
feat(crates-io): update substrate deps on crates-io (#3704)
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop authored Jan 31, 2024
1 parent 24d905e commit 6866201
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 42 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions gcli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ tokio = { workspace = true, features = [ "full" ] }
whoami.workspace = true
reqwest = { workspace = true, default-features = false, features = [ "json", "rustls-tls" ] }
etc.workspace = true
sp-io = { workspace = true, features = [ "std" ] }
sp-core = { workspace = true, features = [ "std" ] }
runtime-primitives.workspace = true
# TODO: use wasmi from workspace (#3214)
wasmi = { version = "0.30.0", features = ["std"] }
Expand Down
2 changes: 1 addition & 1 deletion gcli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::keystore;
use clap::Parser;
use color_eyre::{eyre::eyre, Result};
use env_logger::{Builder, Env};
use gsdk::{signer::Signer, Api};
use gsdk::{ext::sp_core, signer::Signer, Api};

/// Command line gear program application abstraction.
///
Expand Down
13 changes: 0 additions & 13 deletions gcli/tests/gear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,11 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use common::env;
use gsdk::{result::Error, Api};
use std::path::PathBuf;

mod cmd;
mod common;

#[tokio::test]
async fn api_timeout() {
let error = Api::new_with_timeout(None, Some(0)).await.err();
assert!(
matches!(
error,
Some(Error::SubxtRpc(jsonrpsee::core::Error::Transport(..)))
),
"Unexpected error occurred: {error:?}"
);
}

#[test]
fn paths() {
[
Expand Down
34 changes: 34 additions & 0 deletions gsdk/tests/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// This file is part of Gear.

// Copyright (C) 2022-2024 Gear Technologies Inc.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use gsdk::Api;

#[tokio::test]
async fn timeout() {
let error = Api::new_with_timeout(None, Some(0)).await.err();
// NOTE:
//
// There are two kinds of timeout error provided by subxt:
//
// - client request timeout
// - transport timeout
assert!(
format!("{error:?}").to_lowercase().contains("timeout"),
"Unexpected error occurred: {error:?}"
);
}
80 changes: 67 additions & 13 deletions utils/crates-io/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ use anyhow::Result;
use cargo_metadata::Package;
use toml_edit::Document;

/// The working version of sp-wasm-interface.
pub const GP_RUNTIME_INTERFACE_VERSION: &str = "18.0.0";

/// Get the crates-io name of the provided package.
pub fn crates_io_name(pkg: &str) -> &str {
// `gear-core-processor` is taken by others, see the docs
Expand Down Expand Up @@ -65,7 +68,12 @@ pub fn patch_alias(index: &mut Vec<&str>) {
pub fn patch_workspace(name: &str, table: &mut toml_edit::InlineTable) {
match name {
"core-processor" | "gear-core-processor" => core_processor::patch_workspace(name, table),
sub if sub.starts_with("sp-") => substrate::patch_workspace(name, table),
sub if ["sc-", "sp-", "frame-", "try-runtime-cli"]
.iter()
.any(|p| sub.starts_with(p)) =>
{
substrate::patch_workspace(name, table)
}
_ => {}
}
}
Expand Down Expand Up @@ -138,7 +146,7 @@ mod gmeta_codegen {
}

mod runtime_interface {
use crate::GP_RUNTIME_INTERFACE_VERSION;
use super::GP_RUNTIME_INTERFACE_VERSION;
use toml_edit::Document;

/// Patch the manifest of runtime-interface.
Expand Down Expand Up @@ -189,40 +197,86 @@ mod sandbox_host {

/// substrate handler.
mod substrate {
use crate::GP_RUNTIME_INTERFACE_VERSION;
use super::GP_RUNTIME_INTERFACE_VERSION;
use toml_edit::InlineTable;

/// Patch the substrate packages in the manifest of workspace.
///
/// Substrate packages on crates-io currently have no version management
/// (<https://github.com/paritytech/polkadot-sdk/issues/2809>),
/// the following versions are pinned to frame-support-v22.0.0 on crates-io
/// now, <https://crates.io/crates/frame-system/22.0.0/dependencies> for
/// the details.
///
/// NOTE: The packages inside of this function are located at
/// <https://github.com/gear-tech/substrate/tree/cl/v1.0.x-crates-io>.
/// <https://github.com/gear-tech/substrate/tree/cl/v1.1.x-crates-io>.
pub fn patch_workspace(name: &str, table: &mut InlineTable) {
match name {
"frame-support" | "frame-system" | "sp-core" => {
table.insert("version", "22.0.0".into());
}
"frame-support-test" => return,
"frame-benchmarking-cli" => {
table.insert("version", "26.0.0".into());
}
"sc-cli" => {
table.insert("version", "0.30.0".into());
}
"sc-client-db" | "sc-service" => {
table.insert("version", "0.29.0".into());
}
"sp-api" | "sp-rpc" => {
table.insert("version", "20.0.0".into());
}
"sp-arithmetic" => {
table.insert("version", "17.0.0".into());
}
"sp-debug-derive" | "sp-std" => {
table.insert("version", "9.0.0".into());
}
"sp-io" => {
table.insert("version", "24.0.0".into());
}
"sp-runtime" => {
table.insert("version", "25.0.0".into());
}
"sp-version" => {
table.insert("version", "23.0.0".into());
}
"sp-weights" => {
table.insert("version", "21.0.0".into());
}
"try-runtime-cli" => {
table.insert("version", "0.32.0".into());
}
// sp-allocator is outdated on crates.io, last
// 3.0.0 forever, here we use gp-allocator instead.
"sp-allocator" => {
table.insert("version", "4.1.1".into());
table.insert("version", "4.1.2".into());
table.insert("package", "gp-allocator".into());
}
// Our sp-wasm-interface is different from the
// original one.
// Our sp-wasm-interface is different from the substrate one.
//
// ref: sp-wasm-interface-15.0.0
"sp-wasm-interface" => {
table.insert("package", "gp-wasm-interface".into());
table.insert("version", "7.0.1".into());
table.insert("version", "15.0.0".into());
}
// Related to sp-wasm-interface.
//
// no ref bcz we own this package.
"sp-wasm-interface-common" => {
table.insert("version", "7.0.1".into());
table.insert("version", "15.0.0".into());
}
// Related to sp-wasm-interface.
//
// ref:
// - sp-runtime-interface-18.0.0
// - sp-runtime-interface-proc-macro-12.0.0
"sp-runtime-interface" => {
table.insert("version", GP_RUNTIME_INTERFACE_VERSION.into());
table.insert("package", "gp-runtime-interface".into());
}
// The versions of these packages on crates.io are incorrect.
"sp-arithmetic" | "sp-core" | "sp-rpc" | "sp-version" => {
table.insert("version", "21.0.0".into());
}
_ => {}
}

Expand Down
21 changes: 10 additions & 11 deletions utils/crates-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,26 @@ pub const PACKAGE_ALIAS: [(&str, &str); 2] = [
("gear-runtime-primitives", "runtime-primitives"),
];

/// The working version of sp-wasm-interface.
pub const GP_RUNTIME_INTERFACE_VERSION: &str = "7.0.5";

/// Check the input package
pub fn check(manifest: &str) -> Result<ExitStatus> {
Command::new("cargo")
.arg("check")
.arg("--lib")
.arg("--manifest-path")
.arg(manifest)
.args(["check", "--lib", "--manifest-path", manifest])
.status()
.map_err(Into::into)
}

/// Test the input package
pub fn test(package: &str, test: &str) -> Result<ExitStatus> {
Command::new("cargo")
.args(["test", "-p", package, "--", test])
.status()
.map_err(Into::into)
}

/// Publish the input package
pub fn publish(manifest: &str) -> Result<ExitStatus> {
Command::new("cargo")
.arg("publish")
.arg("--manifest-path")
.arg(manifest)
.arg("--allow-dirty")
.args(["publish", "--manifest-path", manifest, "--allow-dirty"])
.status()
.map_err(Into::into)
}
10 changes: 10 additions & 0 deletions utils/crates-io/src/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ impl Publisher {
panic!("Packages {failed:?} failed to pass the check ...");
}

// Post tests for gtest and gclient
for (pkg, test) in [
("demo-syscall-error", "program_can_be_initialized"),
("gsdk", "timeout"),
] {
if !crate::test(pkg, test)?.success() {
panic!("{pkg}:{test} failed to pass the test ...");
}
}

Ok(())
}

Expand Down

0 comments on commit 6866201

Please sign in to comment.