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

feat: re-export used deps from reth-codecs #13167

Merged
merged 3 commits into from
Dec 6, 2024
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
3 changes: 1 addition & 2 deletions crates/storage/codecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ op-alloy-consensus = { workspace = true, optional = true }

# misc
bytes.workspace = true
modular-bitfield = { workspace = true, optional = true }
modular-bitfield.workspace = true
visibility = { version = "0.1.1", optional = true}
serde.workspace = true
arbitrary = { workspace = true, features = ["derive"], optional = true }
Expand Down Expand Up @@ -65,7 +65,6 @@ alloy = [
"dep:alloy-consensus",
"dep:alloy-eips",
"dep:alloy-genesis",
"dep:modular-bitfield",
"dep:alloy-trie",
]
op = ["alloy", "dep:op-alloy-consensus"]
Expand Down
9 changes: 7 additions & 2 deletions crates/storage/codecs/derive/src/compact/flags.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use super::*;
use syn::Attribute;

/// Generates the flag fieldset struct that is going to be used to store the length of fields and
/// their potential presence.
pub(crate) fn generate_flag_struct(
ident: &Ident,
attrs: &[Attribute],
has_lifetime: bool,
fields: &FieldList,
is_zstd: bool,
Expand All @@ -13,6 +15,8 @@ pub(crate) fn generate_flag_struct(
let flags_ident = format_ident!("{ident}Flags");
let mod_flags_ident = format_ident!("{ident}_flags");

let reth_codecs = parse_reth_codecs_path(attrs).unwrap();

let mut field_flags = vec![];

let total_bits = if is_enum {
Expand Down Expand Up @@ -88,8 +92,9 @@ pub(crate) fn generate_flag_struct(
pub use #mod_flags_ident::#flags_ident;
#[allow(non_snake_case)]
mod #mod_flags_ident {
use bytes::Buf;
use modular_bitfield::prelude::*;
use #reth_codecs::__private::Buf;
use #reth_codecs::__private::modular_bitfield;
use #reth_codecs::__private::modular_bitfield::prelude::*;

#[doc = #docs]
#[bitfield]
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/codecs/derive/src/compact/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ fn generate_to_compact(fields: &FieldList, ident: &Ident, is_zstd: bool) -> Vec<
}

/// Function to extract the crate path from `reth_codecs(crate = "...")` attribute.
fn parse_reth_codecs_path(attrs: &[Attribute]) -> syn::Result<syn::Path> {
pub(crate) fn parse_reth_codecs_path(attrs: &[Attribute]) -> syn::Result<syn::Path> {
// let default_crate_path: syn::Path = syn::parse_str("reth-codecs").unwrap();
let mut reth_codecs_path: syn::Path = syn::parse_quote!(reth_codecs);
for attr in attrs {
Expand Down
9 changes: 5 additions & 4 deletions crates/storage/codecs/derive/src/compact/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn derive(input: TokenStream, is_zstd: bool) -> TokenStream {
let has_lifetime = has_lifetime(&generics);

let fields = get_fields(&data);
output.extend(generate_flag_struct(&ident, has_lifetime, &fields, is_zstd));
output.extend(generate_flag_struct(&ident, &attrs, has_lifetime, &fields, is_zstd));
output.extend(generate_from_to(&ident, &attrs, has_lifetime, &fields, is_zstd));
output.into()
}
Expand Down Expand Up @@ -235,7 +235,7 @@ mod tests {
let mut output = quote! {};
let DeriveInput { ident, data, attrs, .. } = parse2(f_struct).unwrap();
let fields = get_fields(&data);
output.extend(generate_flag_struct(&ident, false, &fields, false));
output.extend(generate_flag_struct(&ident, &attrs, false, &fields, false));
output.extend(generate_from_to(&ident, &attrs, false, &fields, false));

// Expected output in a TokenStream format. Commas matter!
Expand All @@ -255,8 +255,9 @@ mod tests {

#[allow(non_snake_case)]
mod TestStruct_flags {
use bytes::Buf;
use modular_bitfield::prelude::*;
use reth_codecs::__private::Buf;
use reth_codecs::__private::modular_bitfield;
use reth_codecs::__private::modular_bitfield::prelude::*;
#[doc = "Fieldset that facilitates compacting the parent type. Used bytes: 2 | Unused bits: 1"]
#[bitfield]
#[derive(Clone, Copy, Debug, Default)]
Expand Down
5 changes: 5 additions & 0 deletions crates/storage/codecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ pub mod txtype;
#[cfg(any(test, feature = "test-utils"))]
pub mod test_utils;

// Used by generated code and doc tests. Not public API.
#[doc(hidden)]
#[path = "private.rs"]
pub mod __private;

/// Trait that implements the `Compact` codec.
///
/// When deriving the trait for custom structs, be aware of certain limitations/recommendations:
Expand Down
3 changes: 3 additions & 0 deletions crates/storage/codecs/src/private.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub use modular_bitfield;

pub use bytes::Buf;
Loading