Skip to content

Commit 8417473

Browse files
chore(no_std): fixed no_std compiler errors in reth-primitives-traits (paradigmxyz#9572)
Co-authored-by: Matthias Seitz <[email protected]>
1 parent 38bc7a1 commit 8417473

File tree

9 files changed

+33
-10
lines changed

9 files changed

+33
-10
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ reth-payload-builder = { path = "crates/payload/builder" }
341341
reth-payload-primitives = { path = "crates/payload/primitives" }
342342
reth-payload-validator = { path = "crates/payload/validator" }
343343
reth-primitives = { path = "crates/primitives" }
344-
reth-primitives-traits = { path = "crates/primitives-traits" }
344+
reth-primitives-traits = { path = "crates/primitives-traits", default-features = false }
345345
reth-provider = { path = "crates/storage/provider" }
346346
reth-prune = { path = "crates/prune/prune" }
347347
reth-prune-types = { path = "crates/prune/types" }

crates/optimism/cli/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ reth-consensus.workspace = true
1717
reth-db = { workspace = true, features = ["mdbx"] }
1818
reth-db-api.workspace = true
1919
reth-downloaders.workspace = true
20-
reth-optimism-primitives.workspace = true
2120
reth-provider.workspace = true
2221
reth-prune.workspace = true
2322
reth-stages.workspace = true
@@ -26,6 +25,9 @@ reth-execution-types.workspace = true
2625
reth-node-core.workspace = true
2726
reth-primitives.workspace = true
2827

28+
## optimisim
29+
reth-optimism-primitives.workspace = true
30+
2931
reth-chainspec.workspace = true
3032
reth-stages-types.workspace = true
3133
reth-node-events.workspace = true

crates/primitives-traits/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ derive_more.workspace = true
2525
revm-primitives = { workspace = true, features = ["serde"] }
2626

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

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

4241
[dev-dependencies]
42+
alloy-primitives = { workspace = true, features = ["arbitrary"] }
43+
alloy-consensus = { workspace = true, features = ["arbitrary"] }
4344
arbitrary = { workspace = true, features = ["derive"] }
4445
proptest.workspace = true
4546
proptest-arbitrary-interop.workspace = true
@@ -50,10 +51,12 @@ serde_json.workspace = true
5051

5152
[features]
5253
default = ["std"]
53-
std = ["thiserror-no-std/std"]
54+
std = []
5455
test-utils = ["arbitrary"]
5556
arbitrary = [
57+
"std",
5658
"alloy-consensus/arbitrary",
59+
"alloy-primitives/arbitrary",
5760
"dep:arbitrary",
5861
"dep:proptest",
5962
"dep:proptest-arbitrary-interop",

crates/primitives-traits/src/constants/gas_units.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::time::Duration;
1+
use core::time::Duration;
2+
3+
#[cfg(not(feature = "std"))]
4+
use alloc::string::String;
25

36
/// Represents one Kilogas, or `1_000` gas.
47
pub const KILOGAS: u64 = 1_000;

crates/primitives-traits/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use core::{
55

66
#[cfg(not(feature = "std"))]
77
use alloc::boxed::Box;
8+
#[cfg(not(feature = "std"))]
9+
extern crate alloc;
810

911
/// A pair of values, one of which is expected and one of which is actual.
1012
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]

crates/primitives-traits/src/integer_list.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,26 @@ impl<'a> Arbitrary<'a> for IntegerList {
140140
}
141141

142142
/// Primitives error type.
143-
#[derive(Debug, thiserror_no_std::Error)]
143+
#[derive(Debug)]
144144
pub enum RoaringBitmapError {
145145
/// The provided input is invalid.
146-
#[error("the provided input is invalid")]
147146
InvalidInput,
148147
/// Failed to deserialize data into type.
149-
#[error("failed to deserialize data into type")]
150148
FailedToDeserialize,
151149
}
152150

151+
#[cfg(feature = "std")]
152+
impl std::error::Error for RoaringBitmapError {}
153+
154+
impl fmt::Display for RoaringBitmapError {
155+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
156+
match self {
157+
Self::InvalidInput => f.write_str("the provided input is invalid"),
158+
Self::FailedToDeserialize {} => f.write_str("failed to deserialize data into type"),
159+
}
160+
}
161+
}
162+
153163
#[cfg(test)]
154164
mod tests {
155165
use super::*;

crates/primitives-traits/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
1010
#![cfg_attr(not(feature = "std"), no_std)]
1111

12+
#[cfg(not(feature = "std"))]
13+
#[macro_use]
14+
extern crate alloc;
15+
1216
#[cfg(feature = "alloy-compat")]
1317
mod alloy_compat;
1418

crates/primitives/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ secp256k1.workspace = true
8787

8888
[features]
8989
default = ["c-kzg", "alloy-compat", "std", "reth-codec"]
90-
std = ["thiserror-no-std/std"]
90+
std = ["thiserror-no-std/std", "reth-primitives-traits/std"]
9191
reth-codec = ["dep:reth-codecs", "dep:zstd", "dep:modular-bitfield"]
9292
asm-keccak = ["alloy-primitives/asm-keccak"]
9393
arbitrary = [

0 commit comments

Comments
 (0)