Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(no_std): fixed no_std compiler errors in reth-primitives-traits #9572

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion 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 @@ -340,7 +340,7 @@ reth-payload-builder = { path = "crates/payload/builder" }
reth-payload-primitives = { path = "crates/payload/primitives" }
reth-payload-validator = { path = "crates/payload/validator" }
reth-primitives = { path = "crates/primitives" }
reth-primitives-traits = { path = "crates/primitives-traits" }
reth-primitives-traits = { path = "crates/primitives-traits", default-features = false }
reth-provider = { path = "crates/storage/provider" }
reth-prune = { path = "crates/prune/prune" }
reth-prune-types = { path = "crates/prune/types" }
Expand Down
4 changes: 3 additions & 1 deletion crates/optimism/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ reth-consensus.workspace = true
reth-db = { workspace = true, features = ["mdbx"] }
reth-db-api.workspace = true
reth-downloaders.workspace = true
reth-optimism-primitives.workspace = true
reth-provider.workspace = true
reth-prune.workspace = true
reth-stages.workspace = true
Expand All @@ -26,6 +25,9 @@ reth-execution-types.workspace = true
reth-node-core.workspace = true
reth-primitives.workspace = true

## optimisim
reth-optimism-primitives.workspace = true

reth-chainspec.workspace = true
reth-stages-types.workspace = true
reth-node-events.workspace = true
Expand Down
7 changes: 5 additions & 2 deletions crates/primitives-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ derive_more.workspace = true
revm-primitives = { workspace = true, features = ["serde"] }

# misc
thiserror-no-std = { workspace = true, default-features = false }
roaring = "0.10.2"
byteorder = "1"

Expand All @@ -40,6 +39,8 @@ proptest = { workspace = true, optional = true }
proptest-arbitrary-interop = { workspace = true, optional = true }

[dev-dependencies]
alloy-primitives = { workspace = true, features = ["arbitrary"] }
alloy-consensus = { workspace = true, features = ["arbitrary"] }
arbitrary = { workspace = true, features = ["derive"] }
proptest.workspace = true
proptest-arbitrary-interop.workspace = true
Expand All @@ -50,10 +51,12 @@ serde_json.workspace = true

[features]
default = ["std"]
std = ["thiserror-no-std/std"]
std = []
test-utils = ["arbitrary"]
arbitrary = [
"std",
"alloy-consensus/arbitrary",
"alloy-primitives/arbitrary",
"dep:arbitrary",
"dep:proptest",
"dep:proptest-arbitrary-interop",
Expand Down
5 changes: 4 additions & 1 deletion crates/primitives-traits/src/constants/gas_units.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::time::Duration;
use core::time::Duration;

#[cfg(not(feature = "std"))]
use alloc::string::String;

/// Represents one Kilogas, or `1_000` gas.
pub const KILOGAS: u64 = 1_000;
Expand Down
2 changes: 2 additions & 0 deletions crates/primitives-traits/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use core::{

#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
#[cfg(not(feature = "std"))]
extern crate alloc;

/// A pair of values, one of which is expected and one of which is actual.
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down
16 changes: 13 additions & 3 deletions crates/primitives-traits/src/integer_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,26 @@ impl<'a> Arbitrary<'a> for IntegerList {
}

/// Primitives error type.
#[derive(Debug, thiserror_no_std::Error)]
#[derive(Debug)]
pub enum RoaringBitmapError {
/// The provided input is invalid.
#[error("the provided input is invalid")]
InvalidInput,
/// Failed to deserialize data into type.
#[error("failed to deserialize data into type")]
FailedToDeserialize,
}

#[cfg(feature = "std")]
impl std::error::Error for RoaringBitmapError {}

impl fmt::Display for RoaringBitmapError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidInput => f.write_str("the provided input is invalid"),
Self::FailedToDeserialize {} => f.write_str("failed to deserialize data into type"),
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
4 changes: 4 additions & 0 deletions crates/primitives-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;

#[cfg(feature = "alloy-compat")]
mod alloy_compat;

Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ secp256k1.workspace = true

[features]
default = ["c-kzg", "alloy-compat", "std", "reth-codec"]
std = ["thiserror-no-std/std"]
std = ["thiserror-no-std/std", "reth-primitives-traits/std"]
reth-codec = ["dep:reth-codecs", "dep:zstd", "dep:modular-bitfield"]
asm-keccak = ["alloy-primitives/asm-keccak"]
arbitrary = [
Expand Down
Loading