From 58c53c02d1e98730cea66598744cb74c8511a210 Mon Sep 17 00:00:00 2001 From: Georges Palauqui Date: Mon, 28 Oct 2024 11:05:56 +0100 Subject: [PATCH 1/9] const_sv2: is a `no_std` crate --- protocols/v2/const-sv2/Cargo.toml | 3 --- protocols/v2/const-sv2/src/lib.rs | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/protocols/v2/const-sv2/Cargo.toml b/protocols/v2/const-sv2/Cargo.toml index f9d49018a..ec759026c 100644 --- a/protocols/v2/const-sv2/Cargo.toml +++ b/protocols/v2/const-sv2/Cargo.toml @@ -13,8 +13,5 @@ keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[features] -no_std = [] - [package.metadata.docs.rs] all-features = true diff --git a/protocols/v2/const-sv2/src/lib.rs b/protocols/v2/const-sv2/src/lib.rs index 2e248a633..4d7829188 100644 --- a/protocols/v2/const-sv2/src/lib.rs +++ b/protocols/v2/const-sv2/src/lib.rs @@ -36,7 +36,7 @@ //! `channel_id`. In this case, the first 4 bytes of the payload represent the //! `channel_id` the message is destined for. -#![cfg_attr(feature = "no_std", no_std)] +#![no_std] /// Identifier for the extension_type field in the SV2 frame, indicating no /// extensions. From 133f73efa1ec3058cc92deaf959ea0e263c1f648 Mon Sep 17 00:00:00 2001 From: Georges Palauqui Date: Mon, 28 Oct 2024 11:50:39 +0100 Subject: [PATCH 2/9] buffer_sv2: is a `no_std`crate by default - only feature `debug` will add `std` dep which is not used by any other crates - just had to replace `std::hint` by its `core` equivalent - in `debug` removed a `mut` to clear a warning --- utils/buffer/src/buffer_pool/mod.rs | 4 ++-- utils/buffer/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/buffer/src/buffer_pool/mod.rs b/utils/buffer/src/buffer_pool/mod.rs index eae9c41ab..705facfd8 100644 --- a/utils/buffer/src/buffer_pool/mod.rs +++ b/utils/buffer/src/buffer_pool/mod.rs @@ -606,7 +606,7 @@ impl Buffer for BufferPool { "{} {} {}", self.inner_memory.raw_offset, self.inner_memory.raw_len, self.inner_memory.len ); - let mut res = self.inner_memory.get_data_owned(shared_state, mode); + let res = self.inner_memory.get_data_owned(shared_state, mode); self.pool_back .set_len_from_inner_memory(self.inner_memory.len); println!( @@ -684,7 +684,7 @@ impl Buffer for BufferPool { impl Drop for BufferPool { fn drop(&mut self) { while self.shared_state.load(Ordering::Relaxed) != 0 { - std::hint::spin_loop(); + core::hint::spin_loop(); } } } diff --git a/utils/buffer/src/lib.rs b/utils/buffer/src/lib.rs index be1d3f8c3..11d1eb0d1 100644 --- a/utils/buffer/src/lib.rs +++ b/utils/buffer/src/lib.rs @@ -1,4 +1,4 @@ -//#![cfg_attr(not(feature = "debug"), no_std)] +#![cfg_attr(not(feature = "debug"), no_std)] //#![feature(backtrace)] mod buffer; From 433d9cbb6faeaec467c8b80b244ed1a77529a538 Mon Sep 17 00:00:00 2001 From: Georges Palauqui Date: Mon, 28 Oct 2024 15:10:06 +0100 Subject: [PATCH 3/9] binary_codec_sv2: is a `no_std` crate by default - std::vec::Vec -> alloc::vec::Vec - std::mem -> core::mem - std::slice -> core::slice - std::convert::{TryFrom, TryInto} -> core::convert::{TryFrom, TryInto} --- .../no-serde-sv2/codec/src/codec/decodable.rs | 2 +- .../no-serde-sv2/codec/src/codec/mod.rs | 2 ++ .../codec/src/datatypes/copy_data_types.rs | 2 ++ .../no-serde-sv2/codec/src/datatypes/mod.rs | 4 ++-- .../datatypes/non_copy_data_types/inner.rs | 4 ++-- .../src/datatypes/non_copy_data_types/mod.rs | 6 +++-- .../non_copy_data_types/seq_inner.rs | 4 ++-- .../binary-sv2/no-serde-sv2/codec/src/lib.rs | 23 +++++++++++-------- 8 files changed, 29 insertions(+), 18 deletions(-) diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/decodable.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/decodable.rs index 45389b73a..1ec7037f7 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/decodable.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/decodable.rs @@ -6,7 +6,7 @@ use crate::{ Error, }; use alloc::vec::Vec; -use std::convert::TryFrom; +use core::convert::TryFrom; #[cfg(not(feature = "no_std"))] use std::io::{Cursor, Read}; diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/mod.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/mod.rs index fd626bc8f..a26ae8e72 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/mod.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/mod.rs @@ -11,6 +11,8 @@ mod impls; #[cfg(feature = "with_buffer_pool")] use buffer_sv2::Slice; +use alloc::vec::Vec; + /// Return the encoded byte size or a `Decodable` pub trait SizeHint { fn size_hint(data: &[u8], offset: usize) -> Result; diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/copy_data_types.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/copy_data_types.rs index be6edeadc..690f719fd 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/copy_data_types.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/copy_data_types.rs @@ -1,5 +1,7 @@ //! Copy data types use crate::{codec::Fixed, datatypes::Sv2DataType, Error}; + +use alloc::vec::Vec; use core::convert::{TryFrom, TryInto}; #[cfg(not(feature = "no_std"))] diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/mod.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/mod.rs index ad1bce76c..8ab1bc924 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/mod.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/mod.rs @@ -12,11 +12,11 @@ pub use non_copy_data_types::{ B0255, B032, B064K, U256, }; +use alloc::vec::Vec; +use core::convert::TryInto; #[cfg(not(feature = "no_std"))] use std::io::{Error as E, Read, Write}; -use std::convert::TryInto; - pub trait Sv2DataType<'a>: Sized + SizeHint + GetSize + TryInto { fn from_bytes_(data: &'a mut [u8]) -> Result { Self::size_hint(data, 0)?; diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/inner.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/inner.rs index 1703c5d2e..e0f30bf38 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/inner.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/inner.rs @@ -4,9 +4,9 @@ use crate::{ datatypes::Sv2DataType, Error, }; -use core::convert::TryFrom; -use std::convert::TryInto; +use alloc::vec::Vec; +use core::convert::{TryFrom, TryInto}; #[cfg(not(feature = "no_std"))] use std::io::{Error as E, Read, Write}; diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/mod.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/mod.rs index 9a117786e..40c47a7ba 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/mod.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/mod.rs @@ -1,6 +1,10 @@ #[cfg(feature = "prop_test")] use quickcheck::{Arbitrary, Gen}; +use alloc::string::String; +#[cfg(feature = "prop_test")] +use alloc::vec::Vec; + mod inner; mod seq_inner; @@ -28,7 +32,6 @@ impl<'decoder> From<[u8; 32]> for U256<'decoder> { } } -#[cfg(not(feature = "with_serde"))] #[cfg(feature = "prop_test")] impl<'a> U256<'a> { pub fn from_gen(g: &mut Gen) -> Self { @@ -40,7 +43,6 @@ impl<'a> U256<'a> { } } -#[cfg(not(feature = "with_serde"))] #[cfg(feature = "prop_test")] impl<'a> B016M<'a> { pub fn from_gen(g: &mut Gen) -> Self { diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/seq_inner.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/seq_inner.rs index acc50f15f..9da799ba9 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/seq_inner.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/seq_inner.rs @@ -280,7 +280,7 @@ impl_into_encodable_field_for_seq!(B064K<'a>); impl_into_encodable_field_for_seq!(B016M<'a>); #[cfg(feature = "prop_test")] -impl<'a, T> std::convert::TryFrom> for Vec { +impl<'a, T> core::convert::TryFrom> for Vec { type Error = &'static str; fn try_from(v: Seq0255<'a, T>) -> Result { if v.0.len() > 255 { @@ -292,7 +292,7 @@ impl<'a, T> std::convert::TryFrom> for Vec { } #[cfg(feature = "prop_test")] -impl<'a, T> std::convert::TryFrom> for Vec { +impl<'a, T> core::convert::TryFrom> for Vec { type Error = &'static str; fn try_from(v: Seq064K<'a, T>) -> Result { if v.0.len() > 64 { diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/lib.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/lib.rs index c1172f9da..cbca39977 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/lib.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/lib.rs @@ -19,6 +19,9 @@ //! Seq0255 <-> SEQ0_255[T] //! Seq064K <-> SEQ0_64K[T] //! ``` + +#![cfg_attr(feature = "no_std", no_std)] + #[cfg(not(feature = "no_std"))] use std::io::{Error as E, ErrorKind}; @@ -35,6 +38,8 @@ pub use crate::codec::{ Fixed, GetSize, SizeHint, }; +use alloc::vec::Vec; + #[allow(clippy::wrong_self_convention)] pub fn to_bytes(src: T) -> Result, Error> { let mut result = vec![0_u8; src.get_size()]; @@ -281,7 +286,7 @@ impl From<&[u8]> for CVec { // the std lib) let len = buffer.len(); let ptr = buffer.as_mut_ptr(); - std::mem::forget(buffer); + core::mem::forget(buffer); CVec { data: ptr, @@ -296,7 +301,7 @@ impl From<&[u8]> for CVec { /// # Safety #[no_mangle] pub unsafe extern "C" fn cvec_from_buffer(data: *const u8, len: usize) -> CVec { - let input = std::slice::from_raw_parts(data, len); + let input = core::slice::from_raw_parts(data, len); let mut buffer: Vec = vec![0; len]; buffer.copy_from_slice(input); @@ -305,7 +310,7 @@ pub unsafe extern "C" fn cvec_from_buffer(data: *const u8, len: usize) -> CVec { // cause UB, but it may be unsound due to unclear (to me, at least) guarantees of the std lib) let len = buffer.len(); let ptr = buffer.as_mut_ptr(); - std::mem::forget(buffer); + core::mem::forget(buffer); CVec { data: ptr, @@ -360,7 +365,7 @@ impl<'a, const A: bool, const B: usize, const C: usize, const D: usize> let len = inner.len(); let cap = inner.capacity(); let ptr = inner.as_mut_ptr(); - std::mem::forget(inner); + core::mem::forget(inner); (ptr, len, cap) } @@ -371,7 +376,7 @@ impl<'a, const A: bool, const B: usize, const C: usize, const D: usize> let len = inner.len(); let cap = inner.capacity(); let ptr = inner.as_mut_ptr(); - std::mem::forget(inner); + core::mem::forget(inner); (ptr, len, cap) } @@ -393,7 +398,7 @@ pub unsafe extern "C" fn init_cvec2() -> CVec2 { // cause UB, but it may be unsound due to unclear (to me, at least) guarantees of the std lib) let len = buffer.len(); let ptr = buffer.as_mut_ptr(); - std::mem::forget(buffer); + core::mem::forget(buffer); CVec2 { data: ptr, @@ -412,7 +417,7 @@ pub unsafe extern "C" fn cvec2_push(cvec2: &mut CVec2, cvec: CVec) { let len = buffer.len(); let ptr = buffer.as_mut_ptr(); - std::mem::forget(buffer); + core::mem::forget(buffer); cvec2.data = ptr; cvec2.len = len; @@ -428,7 +433,7 @@ impl<'a, T: Into> From> for CVec2 { let len = v.len(); let capacity = v.capacity(); let data = v.as_mut_ptr(); - std::mem::forget(v); + core::mem::forget(v); Self { data, len, @@ -445,7 +450,7 @@ impl<'a, T: Into> From> for CVec2 { let len = v.len(); let capacity = v.capacity(); let data = v.as_mut_ptr(); - std::mem::forget(v); + core::mem::forget(v); Self { data, len, From 76670d912d59fd2ae9c5d46275f244cd47c5907a Mon Sep 17 00:00:00 2001 From: Georges Palauqui Date: Mon, 28 Oct 2024 14:49:43 +0100 Subject: [PATCH 4/9] derive_codec_sv2: is a `no_std` crate - std::format -> alloc::format - std::vec::Vec -> alloc::vec::Vec - std::string::{String, ToString} -> alloc::string::{String, ToString} --- .../v2/binary-sv2/no-serde-sv2/derive_codec/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/src/lib.rs b/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/src/lib.rs index aef883ba1..1cd3176f3 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/src/lib.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/src/lib.rs @@ -1,4 +1,13 @@ +#![no_std] + +extern crate alloc; extern crate proc_macro; + +use alloc::{ + format, + string::{String, ToString}, + vec::Vec, +}; use core::iter::FromIterator; use proc_macro::{Group, TokenStream, TokenTree}; From 83d07c054e697049071a169582bb4fdad5b1ef96 Mon Sep 17 00:00:00 2001 From: Georges Palauqui Date: Mon, 28 Oct 2024 15:31:15 +0100 Subject: [PATCH 5/9] serde_sv2: is a `no_std` crate no need any feature for `std` stuff, there is none --- protocols/v2/binary-sv2/serde-sv2/Cargo.toml | 3 --- protocols/v2/binary-sv2/serde-sv2/src/lib.rs | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/protocols/v2/binary-sv2/serde-sv2/Cargo.toml b/protocols/v2/binary-sv2/serde-sv2/Cargo.toml index 0b30e2199..b320d8ce1 100644 --- a/protocols/v2/binary-sv2/serde-sv2/Cargo.toml +++ b/protocols/v2/binary-sv2/serde-sv2/Cargo.toml @@ -18,8 +18,5 @@ keywords = ["stratum", "mining", "bitcoin", "protocol"] serde = { version = "1.0.89", features = ["derive", "alloc"], default-features = false } buffer_sv2 = {version = "^1.0.0", path = "../../../../utils/buffer"} -[features] -no_std = [] - [package.metadata.docs.rs] all-features = true \ No newline at end of file diff --git a/protocols/v2/binary-sv2/serde-sv2/src/lib.rs b/protocols/v2/binary-sv2/serde-sv2/src/lib.rs index 6582619d4..8fd26b92f 100644 --- a/protocols/v2/binary-sv2/serde-sv2/src/lib.rs +++ b/protocols/v2/binary-sv2/serde-sv2/src/lib.rs @@ -75,7 +75,7 @@ //! [rkyv1]: https://docs.rs/rkyv/0.4.3/rkyv //! [rkyv2]: https://davidkoloski.me/blog/rkyv-is-faster-than/ -#![cfg_attr(feature = "no_std", no_std)] +#![no_std] #[macro_use] extern crate alloc; From 1a9012a485bb3390c701af55a259502f8348238e Mon Sep 17 00:00:00 2001 From: Georges Palauqui Date: Mon, 28 Oct 2024 16:45:24 +0100 Subject: [PATCH 6/9] binary_sv2: is a `no_std` crate - std::vec::Vec -> alloc::vec::Vec --- protocols/v2/binary-sv2/binary-sv2/Cargo.toml | 2 +- protocols/v2/binary-sv2/binary-sv2/src/lib.rs | 53 ++++++++++++++++++- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/protocols/v2/binary-sv2/binary-sv2/Cargo.toml b/protocols/v2/binary-sv2/binary-sv2/Cargo.toml index 3df8d5e3b..e510417fc 100644 --- a/protocols/v2/binary-sv2/binary-sv2/Cargo.toml +++ b/protocols/v2/binary-sv2/binary-sv2/Cargo.toml @@ -18,7 +18,7 @@ serde_sv2 = {version = "^1.0.0", path = "../serde-sv2", optional = true} serde = { version = "1.0.89", features = ["derive", "alloc"], default-features = false, optional = true } binary_codec_sv2 = {version = "^1.0.0", path = "../no-serde-sv2/codec", optional = true} derive_codec_sv2 = {version = "^1.0.0", path = "../no-serde-sv2/derive_codec", optional = true} -tracing = {version = "0.1"} +tracing = { version = "0.1", default-features = false } [features] default = ["core"] diff --git a/protocols/v2/binary-sv2/binary-sv2/src/lib.rs b/protocols/v2/binary-sv2/binary-sv2/src/lib.rs index ae13b38a6..9429c88ea 100644 --- a/protocols/v2/binary-sv2/binary-sv2/src/lib.rs +++ b/protocols/v2/binary-sv2/binary-sv2/src/lib.rs @@ -1,5 +1,10 @@ // TODO unify errors from serde_sv2 and no-serde-sv2 -// + +#![no_std] + +#[macro_use] +extern crate alloc; + use core::convert::TryInto; #[cfg(feature = "with_serde")] @@ -37,6 +42,8 @@ mod test { mod test_struct { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; use core::convert::TryInto; #[derive(Clone, Deserialize, Serialize, PartialEq, Debug)] @@ -67,6 +74,8 @@ mod test { mod test_f32 { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; use core::convert::TryInto; #[derive(Clone, Deserialize, Serialize, PartialEq, Debug)] @@ -97,6 +106,8 @@ mod test { mod test_b0255 { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; use core::convert::TryInto; #[derive(Clone, Deserialize, Serialize, PartialEq, Debug)] @@ -142,6 +153,8 @@ mod test { mod test_u256 { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; use core::convert::TryInto; #[derive(Clone, Deserialize, Serialize, PartialEq, Debug)] @@ -170,6 +183,8 @@ mod test { mod test_signature { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -198,6 +213,8 @@ mod test { mod test_b016m { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -246,6 +263,8 @@ mod test { mod test_b064k { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -277,6 +296,8 @@ mod test { mod test_seq0255_u256 { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -317,6 +338,8 @@ mod test { mod test_0255_bool { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { @@ -343,6 +366,8 @@ mod test { mod test_seq0255_u16 { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { @@ -369,6 +394,8 @@ mod test { mod test_seq_0255_u24 { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -401,6 +428,8 @@ mod test { mod test_seqo255_u32 { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { @@ -427,6 +456,8 @@ mod test { mod test_seq0255_signature { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -462,6 +493,8 @@ mod test { mod test_seq_064_u256 { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -502,6 +535,8 @@ mod test { mod test_064_bool { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { @@ -536,6 +571,8 @@ mod test { mod test_se1o64k_u16 { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { @@ -562,6 +599,8 @@ mod test { mod test_seq064k_u24 { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -594,6 +633,8 @@ mod test { mod test_seq064k_u32 { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { @@ -619,6 +660,8 @@ mod test { } mod test_seq064k_signature { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -653,6 +696,8 @@ mod test { } mod test_seq064k_b016m { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -687,6 +732,7 @@ mod test { } mod test_seq_0255_in_struct { use super::*; + use alloc::vec::Vec; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { @@ -713,6 +759,8 @@ mod test { } mod test_sv2_option_u256 { use super::*; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -748,7 +796,8 @@ mod test { } mod test_sv2_option_none { use super::*; - use core::convert::TryInto; + #[cfg(not(feature = "with_serde"))] + use alloc::vec::Vec; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { From 537a6acb378b5932231705b1b28ae1cbe01d0bb0 Mon Sep 17 00:00:00 2001 From: Georges Palauqui Date: Mon, 28 Oct 2024 16:55:32 +0100 Subject: [PATCH 7/9] framing_sv2: is a `no_std` crate --- protocols/v2/framing-sv2/Cargo.toml | 3 +-- protocols/v2/framing-sv2/src/lib.rs | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/protocols/v2/framing-sv2/Cargo.toml b/protocols/v2/framing-sv2/Cargo.toml index 6797d7946..0429254ca 100644 --- a/protocols/v2/framing-sv2/Cargo.toml +++ b/protocols/v2/framing-sv2/Cargo.toml @@ -20,8 +20,7 @@ binary_sv2 = { version = "^1.0.0", path = "../../../protocols/v2/binary-sv2/bina buffer_sv2 = { version = "^1.0.0", path = "../../../utils/buffer", optional=true } [features] -no_std = [] -with_serde = ["binary_sv2/with_serde", "serde", "buffer_sv2/with_serde"] +with_serde = ["binary_sv2/with_serde", "serde", "buffer_sv2?/with_serde"] with_buffer_pool = ["binary_sv2/with_buffer_pool", "buffer_sv2"] [package.metadata.docs.rs] diff --git a/protocols/v2/framing-sv2/src/lib.rs b/protocols/v2/framing-sv2/src/lib.rs index a8d9335e7..4096384a9 100644 --- a/protocols/v2/framing-sv2/src/lib.rs +++ b/protocols/v2/framing-sv2/src/lib.rs @@ -23,7 +23,8 @@ //! The `with_serde` feature flag is only used for the Message Generator, and deprecated for any //! other kind of usage. It will likely be fully deprecated in the future. -#![cfg_attr(feature = "no_std", no_std)] +#![no_std] + extern crate alloc; /// SV2 framing types From b4da137ec57a7ef6eb7d5de37a79e012d13021df Mon Sep 17 00:00:00 2001 From: Georges Palauqui Date: Tue, 29 Oct 2024 12:45:27 +0100 Subject: [PATCH 8/9] binary_sv2: factorize `use alloc::vec::Vec;` in tests --- protocols/v2/binary-sv2/binary-sv2/src/lib.rs | 46 +------------------ 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/protocols/v2/binary-sv2/binary-sv2/src/lib.rs b/protocols/v2/binary-sv2/binary-sv2/src/lib.rs index 9429c88ea..85fc6b31b 100644 --- a/protocols/v2/binary-sv2/binary-sv2/src/lib.rs +++ b/protocols/v2/binary-sv2/binary-sv2/src/lib.rs @@ -39,11 +39,10 @@ pub fn u256_from_int>(value: V) -> U256<'static> { #[cfg(test)] mod test { use super::*; + use alloc::vec::Vec; mod test_struct { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; use core::convert::TryInto; #[derive(Clone, Deserialize, Serialize, PartialEq, Debug)] @@ -74,8 +73,6 @@ mod test { mod test_f32 { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; use core::convert::TryInto; #[derive(Clone, Deserialize, Serialize, PartialEq, Debug)] @@ -106,8 +103,6 @@ mod test { mod test_b0255 { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; use core::convert::TryInto; #[derive(Clone, Deserialize, Serialize, PartialEq, Debug)] @@ -153,8 +148,6 @@ mod test { mod test_u256 { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; use core::convert::TryInto; #[derive(Clone, Deserialize, Serialize, PartialEq, Debug)] @@ -183,8 +176,6 @@ mod test { mod test_signature { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -213,8 +204,6 @@ mod test { mod test_b016m { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -263,8 +252,6 @@ mod test { mod test_b064k { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -296,8 +283,6 @@ mod test { mod test_seq0255_u256 { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -338,8 +323,6 @@ mod test { mod test_0255_bool { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { @@ -366,8 +349,6 @@ mod test { mod test_seq0255_u16 { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { @@ -394,8 +375,6 @@ mod test { mod test_seq_0255_u24 { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -428,8 +407,6 @@ mod test { mod test_seqo255_u32 { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { @@ -456,8 +433,6 @@ mod test { mod test_seq0255_signature { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -493,8 +468,6 @@ mod test { mod test_seq_064_u256 { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -535,8 +508,6 @@ mod test { mod test_064_bool { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { @@ -571,8 +542,6 @@ mod test { mod test_se1o64k_u16 { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { @@ -599,8 +568,6 @@ mod test { mod test_seq064k_u24 { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -633,8 +600,6 @@ mod test { mod test_seq064k_u32 { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { @@ -660,8 +625,6 @@ mod test { } mod test_seq064k_signature { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -696,8 +659,6 @@ mod test { } mod test_seq064k_b016m { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -732,7 +693,6 @@ mod test { } mod test_seq_0255_in_struct { use super::*; - use alloc::vec::Vec; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { @@ -759,8 +719,6 @@ mod test { } mod test_sv2_option_u256 { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; use core::convert::TryInto; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -796,8 +754,6 @@ mod test { } mod test_sv2_option_none { use super::*; - #[cfg(not(feature = "with_serde"))] - use alloc::vec::Vec; #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct Test<'decoder> { From 8cd634b26f09e17037c42e5b1db5af623af49627 Mon Sep 17 00:00:00 2001 From: Georges Palauqui Date: Wed, 13 Nov 2024 08:27:17 +0100 Subject: [PATCH 9/9] Add `no_std` in README --- protocols/v2/binary-sv2/binary-sv2/README.md | 3 +++ protocols/v2/binary-sv2/no-serde-sv2/codec/README.md | 3 +++ protocols/v2/binary-sv2/no-serde-sv2/derive_codec/README.md | 3 +++ protocols/v2/binary-sv2/serde-sv2/README.md | 3 +++ protocols/v2/const-sv2/README.md | 2 +- protocols/v2/framing-sv2/README.md | 3 +++ 6 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 protocols/v2/binary-sv2/no-serde-sv2/codec/README.md create mode 100644 protocols/v2/binary-sv2/no-serde-sv2/derive_codec/README.md create mode 100644 protocols/v2/binary-sv2/serde-sv2/README.md create mode 100644 protocols/v2/framing-sv2/README.md diff --git a/protocols/v2/binary-sv2/binary-sv2/README.md b/protocols/v2/binary-sv2/binary-sv2/README.md index e69de29bb..7fac0315f 100644 --- a/protocols/v2/binary-sv2/binary-sv2/README.md +++ b/protocols/v2/binary-sv2/binary-sv2/README.md @@ -0,0 +1,3 @@ +# binary_sv2 + +`binary_sv2` is a Rust `no_std` crate \ No newline at end of file diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/README.md b/protocols/v2/binary-sv2/no-serde-sv2/codec/README.md new file mode 100644 index 000000000..f338a94db --- /dev/null +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/README.md @@ -0,0 +1,3 @@ +# binary_codec_sv2 + +`binary_codec_sv2` is a Rust `no_std` crate \ No newline at end of file diff --git a/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/README.md b/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/README.md new file mode 100644 index 000000000..01af2599e --- /dev/null +++ b/protocols/v2/binary-sv2/no-serde-sv2/derive_codec/README.md @@ -0,0 +1,3 @@ +# derive_codec_sv2 + +`derive_codec_sv2` is a Rust `no_std` crate \ No newline at end of file diff --git a/protocols/v2/binary-sv2/serde-sv2/README.md b/protocols/v2/binary-sv2/serde-sv2/README.md new file mode 100644 index 000000000..43a6706d0 --- /dev/null +++ b/protocols/v2/binary-sv2/serde-sv2/README.md @@ -0,0 +1,3 @@ +# serde_sv2 + +`serde_sv2` is a Rust `no_std` crate \ No newline at end of file diff --git a/protocols/v2/const-sv2/README.md b/protocols/v2/const-sv2/README.md index b49199745..3a414b3cc 100644 --- a/protocols/v2/const-sv2/README.md +++ b/protocols/v2/const-sv2/README.md @@ -5,7 +5,7 @@ [![rustc+](https://img.shields.io/badge/rustc-1.75.0%2B-lightgrey.svg)](https://blog.rust-lang.org/2023/12/28/Rust-1.75.0.html) [![license](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](https://github.com/stratum-mining/stratum/blob/main/LICENSE.md) -`const_sv2` is a Rust crate that provides essential constants for the Sv2 (Stratum V2) protocol. These constants are crucial for message framing, encryption, and protocol-specific identifiers across various Sv2 components, including Mining, Job Declaration, and Template Distribution protocols. +`const_sv2` is a Rust `no_std` crate that provides essential constants for the Sv2 (Stratum V2) protocol. These constants are crucial for message framing, encryption, and protocol-specific identifiers across various Sv2 components, including Mining, Job Declaration, and Template Distribution protocols. ## Key Capabilities diff --git a/protocols/v2/framing-sv2/README.md b/protocols/v2/framing-sv2/README.md new file mode 100644 index 000000000..26e617ed2 --- /dev/null +++ b/protocols/v2/framing-sv2/README.md @@ -0,0 +1,3 @@ +# framing_sv2 + +`framing_sv2` is a Rust `no_std` crate \ No newline at end of file