Skip to content

Commit

Permalink
Use umbrella crate for minimal template (#5155)
Browse files Browse the repository at this point in the history
Co-authored-by: kianenigma <kian@parity.io>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 28, 2024
1 parent ef3a0d8 commit 9cf5e81
Show file tree
Hide file tree
Showing 29 changed files with 136 additions and 337 deletions.
35 changes: 3 additions & 32 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ ahash = { version = "0.8.2" }
alloy-primitives = { version = "0.4.2", default-features = false }
alloy-sol-types = { version = "0.4.2", default-features = false }
always-assert = { version = "0.1" }
anyhow = { version = "1.0.81" }
anyhow = { version = "1.0.81", default-features = false }
aquamarine = { version = "0.5.0" }
arbitrary = { version = "1.3.2" }
ark-bls12-377 = { version = "0.4.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion bridges/relays/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ publish = false
workspace = true

[dependencies]
anyhow = { workspace = true }
anyhow = { workspace = true, default-features = true }
async-std = { workspace = true }
async-trait = { workspace = true }
backoff = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion cumulus/client/consensus/proposer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
workspace = true

[dependencies]
anyhow = { workspace = true }
anyhow = { workspace = true, default-features = true }
async-trait = { workspace = true }
thiserror = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ simple-mermaid = "0.1.1"
docify = { workspace = true }

# Polkadot SDK deps, typically all should only be in scope such that we can link to their doc item.
polkadot-sdk = { features = ["runtime"], workspace = true, default-features = true }
polkadot-sdk = { features = ["runtime-full"], workspace = true, default-features = true }
node-cli = { workspace = true }
kitchensink-runtime = { workspace = true }
chain-spec-builder = { workspace = true, default-features = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ use frame::{
runtime,
},
prelude::*,
runtime::{
apis::{self, impl_runtime_apis, ExtrinsicInclusionMode},
prelude::*,
},
runtime::{apis, prelude::*},
};
use sp_genesis_builder::PresetId;

Expand Down
27 changes: 27 additions & 0 deletions prdoc/pr_5155.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Use umbrella crate for minimal template

doc:
- audience: Runtime Dev
description: |
Minor additions to the `polkadot-sdk-frame` crate and making it ready for usage in more templates. This PR already integrates it in the minimal template.


crates:
- name: polkadot-sdk
bump: major
- name: polkadot-sdk-frame
bump: patch
- name: sp-wasm-interface
bump: patch
- name: pallet-revive
bump: patch
- name: pallet-revive-fixtures
bump: patch
- name: frame-support
bump: patch
- name: pallet-balances
bump: patch

8 changes: 6 additions & 2 deletions scripts/generate-umbrella.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def main(path, version):
# Sort by name
std_crates.sort(key=lambda x: x[0].name)
nostd_crates.sort(key=lambda x: x[0].name)

runtime_crates = [crate for crate in nostd_crates if 'frame' in crate[0].name or crate[0].name.startswith('sp-')]
all_crates = std_crates + nostd_crates
all_crates.sort(key=lambda x: x[0].name)
dependencies = {}
Expand All @@ -105,7 +107,8 @@ def main(path, version):
"serde": [],
"experimental": [],
"with-tracing": [],
"runtime": list([f"{d.name}" for d, _ in nostd_crates]),
"runtime-full": list([f"{d.name}" for d, _ in nostd_crates]),
"runtime": list([f"{d.name}" for d, _ in runtime_crates]),
"node": ["std"] + list([f"{d.name}" for d, _ in std_crates]),
"tuples-96": [],
"riscv": [],
Expand All @@ -120,7 +123,7 @@ def main(path, version):
"description": "Polkadot SDK umbrella crate.",
"license": "Apache-2.0",
"metadata": { "docs": { "rs": {
"features": ["runtime", "node"],
"features": ["runtime-full", "node"],
"targets": ["x86_64-unknown-linux-gnu"]
}}}
},
Expand Down Expand Up @@ -204,3 +207,4 @@ def parse_args():
if __name__ == "__main__":
args = parse_args()
main(args.sdk, args.version)

2 changes: 1 addition & 1 deletion substrate/bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ serde_json = { features = ["alloc", "arbitrary_precision"], workspace = true }
# pallet-asset-conversion: turn on "num-traits" feature
primitive-types = { features = ["codec", "num-traits", "scale-info"], workspace = true }

polkadot-sdk = { features = ["runtime", "tuples-96"], workspace = true }
polkadot-sdk = { features = ["runtime-full", "tuples-96"], workspace = true }

# shared code between runtime and node
node-primitives = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/contracts/fixtures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ workspace = true
[dependencies]
frame-system = { workspace = true, default-features = true }
sp-runtime = { workspace = true, default-features = true }
anyhow = { workspace = true }
anyhow = { workspace = true, default-features = true }

[build-dependencies]
parity-wasm = { workspace = true }
tempfile = { workspace = true }
toml = { workspace = true }
twox-hash = { workspace = true, default-features = true }
polkavm-linker = { workspace = true, optional = true }
anyhow = { workspace = true }
anyhow = { workspace = true, default-features = true }

[features]
riscv = ["polkavm-linker"]
6 changes: 5 additions & 1 deletion substrate/frame/revive/fixtures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ default = ["std"]
# we will remove this once there is an upstream toolchain
riscv = []
# only when std is enabled all fixtures are available
std = ["frame-system", "sp-runtime"]
std = [
"anyhow/std",
"frame-system",
"sp-runtime",
]
27 changes: 20 additions & 7 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,34 @@ pub mod runtime {
pub use frame_executive::*;

/// Macro to amalgamate the runtime into `struct Runtime`.
///
/// Consider using the new version of this [`frame_construct_runtime`].
pub use frame_support::construct_runtime;

/// Macro to amalgamate the runtime into `struct Runtime`.
///
/// This is the newer version of [`construct_runtime`].
pub use frame_support::runtime as frame_construct_runtime;

/// Macro to easily derive the `Config` trait of various pallet for `Runtime`.
pub use frame_support::derive_impl;

/// Macros to easily impl traits such as `Get` for types.
// TODO: using linking in the Get in the line above triggers an ICE :/
pub use frame_support::{ord_parameter_types, parameter_types};

/// For building genesis config.
pub use frame_support::genesis_builder_helper::{build_state, get_preset};

/// Const types that can easily be used in conjuncture with `Get`.
pub use frame_support::traits::{
ConstBool, ConstI128, ConstI16, ConstI32, ConstI64, ConstI8, ConstU128, ConstU16,
ConstU32, ConstU64, ConstU8,
};

/// Used for simple fee calculation.
pub use frame_support::weights::{self, FixedFee, NoFee};

/// Primary types used to parameterize `EnsureOrigin` and `EnsureRootWithArg`.
pub use frame_system::{
EnsureNever, EnsureNone, EnsureRoot, EnsureRootWithSuccess, EnsureSigned,
Expand All @@ -201,11 +214,16 @@ pub mod runtime {
/// Types to define your runtime version.
pub use sp_version::{create_runtime_str, runtime_version, RuntimeVersion};

#[cfg(feature = "std")]
pub use sp_version::NativeVersion;

/// Macro to implement runtime APIs.
pub use sp_api::impl_runtime_apis;

#[cfg(feature = "std")]
pub use sp_version::NativeVersion;
// Types often used in the runtime APIs.
pub use sp_core::OpaqueMetadata;
pub use sp_inherents::{CheckInherentsResult, InherentData};
pub use sp_runtime::{ApplyExtrinsicResult, ExtrinsicInclusionMode};
}

/// Types and traits for runtimes that implement runtime APIs.
Expand All @@ -223,11 +241,6 @@ pub mod runtime {
// moved to file similarly.
#[allow(ambiguous_glob_reexports)]
pub mod apis {
// Types often used in the runtime APIs.
pub use sp_core::OpaqueMetadata;
pub use sp_inherents::{CheckInherentsResult, InherentData};
pub use sp_runtime::{ApplyExtrinsicResult, ExtrinsicInclusionMode};

pub use frame_system_rpc_runtime_api::*;
pub use sp_api::{self, *};
pub use sp_block_builder::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ use frame_support::derive_impl;

mod common;

use common::outer_enums::{pallet, pallet2};

pub type Header = sp_runtime::generic::Header<u32, sp_runtime::traits::BlakeTwo256>;
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<u32, RuntimeCall, (), ()>;
Expand Down Expand Up @@ -75,8 +73,10 @@ frame_support::construct_runtime!(
}
);

#[cfg(feature = "experimental")]
#[test]
fn module_error_outer_enum_expand_explicit() {
use common::outer_enums::{pallet, pallet2};
// The Runtime has *all* parts explicitly defined.

// Check that all error types are propagated
Expand All @@ -90,9 +90,7 @@ fn module_error_outer_enum_expand_explicit() {
frame_system::Error::NonZeroRefCount => (),
frame_system::Error::CallFiltered => (),
frame_system::Error::MultiBlockMigrationsOngoing => (),
#[cfg(feature = "experimental")]
frame_system::Error::InvalidTask => (),
#[cfg(feature = "experimental")]
frame_system::Error::FailedTask => (),
frame_system::Error::NothingAuthorized => (),
frame_system::Error::Unauthorized => (),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ use frame_support::derive_impl;

mod common;

use common::outer_enums::{pallet, pallet2};

pub type Header = sp_runtime::generic::Header<u32, sp_runtime::traits::BlakeTwo256>;
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<u32, RuntimeCall, (), ()>;
Expand Down Expand Up @@ -75,8 +73,10 @@ frame_support::construct_runtime!(
}
);

#[cfg(feature = "experimental")]
#[test]
fn module_error_outer_enum_expand_implicit() {
use common::outer_enums::{pallet, pallet2};
// The Runtime has *all* parts implicitly defined.

// Check that all error types are propagated
Expand All @@ -90,9 +90,7 @@ fn module_error_outer_enum_expand_implicit() {
frame_system::Error::NonZeroRefCount => (),
frame_system::Error::CallFiltered => (),
frame_system::Error::MultiBlockMigrationsOngoing => (),
#[cfg(feature = "experimental")]
frame_system::Error::InvalidTask => (),
#[cfg(feature = "experimental")]
frame_system::Error::FailedTask => (),
frame_system::Error::NothingAuthorized => (),
frame_system::Error::Unauthorized => (),
Expand Down
6 changes: 5 additions & 1 deletion substrate/primitives/wasm-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ anyhow = { optional = true, workspace = true }

[features]
default = ["std"]
std = ["codec/std", "log/std"]
std = [
"anyhow?/std",
"codec/std",
"log/std",
]
wasmtime = ["anyhow", "dep:wasmtime"]
33 changes: 3 additions & 30 deletions templates/minimal/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,15 @@ futures-timer = { workspace = true }
jsonrpsee = { features = ["server"], workspace = true }
serde_json = { workspace = true, default-features = true }

sc-cli = { workspace = true, default-features = true }
sc-executor = { workspace = true, default-features = true }
sc-network = { workspace = true, default-features = true }
sc-service = { workspace = true, default-features = true }
sc-telemetry = { workspace = true, default-features = true }
sc-transaction-pool = { workspace = true, default-features = true }
sc-transaction-pool-api = { workspace = true, default-features = true }
sc-consensus = { workspace = true, default-features = true }
sc-consensus-manual-seal = { workspace = true, default-features = true }
sc-basic-authorship = { workspace = true, default-features = true }
sc-offchain = { workspace = true, default-features = true }
sc-client-api = { workspace = true, default-features = true }

sp-timestamp = { workspace = true, default-features = true }
sp-keyring = { workspace = true, default-features = true }
sp-api = { workspace = true, default-features = true }
sp-blockchain = { workspace = true, default-features = true }
sp-block-builder = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }
sp-runtime = { workspace = true, default-features = true }

substrate-frame-rpc-system = { workspace = true, default-features = true }

# Once the native runtime is gone, there should be little to no dependency on FRAME here, and
# certainly no dependency on the runtime.
frame = { features = [
"experimental",
"runtime",
], workspace = true, default-features = true }
polkadot-sdk = { workspace = true, features = ["experimental", "node"] }
minimal-template-runtime = { workspace = true }

[build-dependencies]
substrate-build-script-utils = { workspace = true, default-features = true }
polkadot-sdk = { workspace = true, features = ["substrate-build-script-utils"] }

[features]
default = ["std"]
std = [
"minimal-template-runtime/std",
"polkadot-sdk/std",
]
2 changes: 1 addition & 1 deletion templates/minimal/node/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed};
use polkadot_sdk::substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed};

fn main() {
generate_cargo_keys();
Expand Down
Loading

0 comments on commit 9cf5e81

Please sign in to comment.