From 169eab2bd55db90ee7a3c31919b9f92835792519 Mon Sep 17 00:00:00 2001 From: Longarithm Date: Thu, 11 Jul 2024 02:52:46 +0400 Subject: [PATCH] flags, udeps --- Cargo.toml | 2 ++ core/primitives-core/Cargo.toml | 5 +++++ core/primitives-core/src/lib.rs | 2 +- core/primitives/Cargo.toml | 8 ++++++-- core/primitives/src/lib.rs | 2 +- core/structs-checker/Cargo.toml | 5 +++++ core/structs-checker/src/lib.rs | 4 ++-- tools/protocol-schema-check/README.md | 2 +- tools/protocol-schema-check/build.rs | 3 --- .../res/protocol_structs.toml | 6 ++++++ tools/protocol-schema-check/src/main.rs | 14 ++++++-------- 11 files changed, 35 insertions(+), 18 deletions(-) delete mode 100644 tools/protocol-schema-check/build.rs diff --git a/Cargo.toml b/Cargo.toml index f7cebf041ea..fca7c27c5e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -115,6 +115,8 @@ len_zero = "deny" or_fun_call = "deny" unnecessary_lazy_evaluations = "deny" +[workspace.lints.rust] +unexpected_cfgs = { level = "allow", check-cfg = ['cfg(enable_const_type_id)'] } [workspace.dependencies] actix = "0.13.0" diff --git a/core/primitives-core/Cargo.toml b/core/primitives-core/Cargo.toml index d40d956aa21..60c942461f0 100644 --- a/core/primitives-core/Cargo.toml +++ b/core/primitives-core/Cargo.toml @@ -55,8 +55,13 @@ nightly_protocol = [ ] statelessnet_protocol = [] + protocol_schema = [ "near-structs-checker/protocol_schema", "near-structs-checker-core", "inventory", ] + +[package.metadata.cargo-udeps.ignore] +# Protocol schema checks require external dependencies for sanity checker tool. +normal = ["near-structs-checker-core", "inventory"] diff --git a/core/primitives-core/src/lib.rs b/core/primitives-core/src/lib.rs index c4ead946ff2..03b680d625d 100644 --- a/core/primitives-core/src/lib.rs +++ b/core/primitives-core/src/lib.rs @@ -1,4 +1,4 @@ -#![cfg_attr(protocol_schema, feature(const_type_id))] +#![cfg_attr(enable_const_type_id, feature(const_type_id))] pub use borsh; pub use num_rational; diff --git a/core/primitives/Cargo.toml b/core/primitives/Cargo.toml index 8982e8be4b3..a06d2c6b1f5 100644 --- a/core/primitives/Cargo.toml +++ b/core/primitives/Cargo.toml @@ -95,14 +95,14 @@ statelessnet_protocol = ["near-primitives-core/statelessnet_protocol"] new_epoch_sync = [] default = ["near-primitives/rand"] +calimero_zero_storage = [] + protocol_schema = [ "near-primitives-core/protocol_schema", "near-structs-checker-core", "inventory" ] -calimero_zero_storage = [] - [dev-dependencies] chrono = { workspace = true, features = ["clock"] } near-primitives = { workspace = true, features = ["clock", "solomon", "rand"] } @@ -117,3 +117,7 @@ regex.workspace = true [[bench]] name = "serialization" harness = false + +[package.metadata.cargo-udeps.ignore] +# Protocol schema checks require external dependencies for sanity checker tool. +normal = ["near-structs-checker-core", "inventory"] diff --git a/core/primitives/src/lib.rs b/core/primitives/src/lib.rs index 1fde0e048d0..be812f59060 100644 --- a/core/primitives/src/lib.rs +++ b/core/primitives/src/lib.rs @@ -1,4 +1,4 @@ -#![cfg_attr(const_type_id, feature(const_type_id))] +#![cfg_attr(enable_const_type_id, feature(const_type_id))] pub use near_primitives_core::account; pub use near_primitives_core::apply; diff --git a/core/structs-checker/Cargo.toml b/core/structs-checker/Cargo.toml index 852079172d6..ff080efea27 100644 --- a/core/structs-checker/Cargo.toml +++ b/core/structs-checker/Cargo.toml @@ -23,9 +23,14 @@ syn = { workspace = true, optional = true } near-structs-checker-core = { path = "../structs-checker-core" } [features] + protocol_schema = [ "near-structs-checker-core/protocol_schema", "proc-macro2", "syn", "quote" ] + +[package.metadata.cargo-udeps.ignore] +# Protocol schema checks require external dependencies for sanity checker tool. +normal = ["proc-macro2", "syn", "quote"] diff --git a/core/structs-checker/src/lib.rs b/core/structs-checker/src/lib.rs index 2ef09dc3bd4..3919387e3f1 100644 --- a/core/structs-checker/src/lib.rs +++ b/core/structs-checker/src/lib.rs @@ -5,7 +5,7 @@ pub fn protocol_struct(input: TokenStream) -> TokenStream { helper::protocol_struct_impl(input) } -#[cfg(all(const_type_id, feature = "protocol_schema"))] +#[cfg(all(enable_const_type_id, feature = "protocol_schema"))] mod helper { use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; @@ -118,7 +118,7 @@ mod helper { } } -#[cfg(not(all(const_type_id, feature = "protocol_schema")))] +#[cfg(not(all(enable_const_type_id, feature = "protocol_schema")))] mod helper { use proc_macro::TokenStream; diff --git a/tools/protocol-schema-check/README.md b/tools/protocol-schema-check/README.md index e39e0c155d6..8d355475117 100644 --- a/tools/protocol-schema-check/README.md +++ b/tools/protocol-schema-check/README.md @@ -20,7 +20,7 @@ For context on why this tool is necessary, refer to [this pull request](https:// ## Usage Run the tool locally using: -`cargo +nightly run -p protocol-schema-check` +`RUSTFLAGS="--cfg enable_const_type_id" cargo +nightly run -p protocol-schema-check` ## What To Do If It Fails diff --git a/tools/protocol-schema-check/build.rs b/tools/protocol-schema-check/build.rs deleted file mode 100644 index 002b164bcaf..00000000000 --- a/tools/protocol-schema-check/build.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("cargo:rustc-cfg=const_type_id"); -} diff --git a/tools/protocol-schema-check/res/protocol_structs.toml b/tools/protocol-schema-check/res/protocol_structs.toml index e69de29bb2d..1d0d2c782ba 100644 --- a/tools/protocol-schema-check/res/protocol_structs.toml +++ b/tools/protocol-schema-check/res/protocol_structs.toml @@ -0,0 +1,6 @@ +AccessKey = 3914867406 +Account = 3785422552 +AccountV2 = 3850278944 +CryptoHash = 1506996321 +LegacyAccount = 1274590952 +ValidatorKickoutReason = 1209594351 diff --git a/tools/protocol-schema-check/src/main.rs b/tools/protocol-schema-check/src/main.rs index 80085bf283f..5a11ac45eca 100644 --- a/tools/protocol-schema-check/src/main.rs +++ b/tools/protocol-schema-check/src/main.rs @@ -25,17 +25,17 @@ fn compute_hash( ) -> u32 { let mut hasher = DefaultHasher::new(); match info { - ProtocolStructInfo::Struct { name, type_id, fields } => { + ProtocolStructInfo::Struct { name, type_id: _, fields } => { name.hash(&mut hasher); - type_id.hash(&mut hasher); + // type_id.hash(&mut hasher); for (field_name, field_type_id) in *fields { field_name.hash(&mut hasher); compute_type_hash(*field_type_id, structs, &mut hasher); } } - ProtocolStructInfo::Enum { name, type_id, variants } => { + ProtocolStructInfo::Enum { name, type_id: _, variants } => { name.hash(&mut hasher); - type_id.hash(&mut hasher); + // type_id.hash(&mut hasher); for (variant_name, variant_fields) in *variants { variant_name.hash(&mut hasher); if let Some(fields) = variant_fields { @@ -61,14 +61,12 @@ fn compute_type_hash( // Likely a primitive or external type, hash the type_id directly. // TODO (#11755): proper implementation for generics. Or require a // separate type for them. - type_id.hash(hasher); + // type_id.hash(hasher); + 0.hash(hasher); } } fn main() { - #[cfg(all(const_type_id, feature = "protocol_schema"))] - println!("CONST TYPE ID ON"); - let file_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("res").join("protocol_structs.toml"); let stored_hashes: BTreeMap = if file_path.exists() {