libbpf-rs icon indicating copy to clipboard operation
libbpf-rs copied to clipboard

Customize derives for libbpf-cargo generated types

Open kxxt opened this issue 3 months ago • 3 comments

Currently, there is no way to add custom derives to libbpf-cargo generated types.

My intended usage of this is to derive https://docs.rs/zerocopy/latest/zerocopy/trait.FromBytes.html for some generated structs to access them(which could come from bpf ringbuf as &[u8]) in a safe, zero-copy and idiomatic way in rust.

kxxt avatar Sep 21 '25 12:09 kxxt

I am not sure there is a good way to inject custom derives. That being said, we have https://github.com/libbpf/libbpf-rs/issues/350 which would hopefully either make us come up with a general way for interpreting certain types as bytes or plug in some kind extension mechanism for interaction with other crates. Alas, this issue is a bit on the back burner right now.

danielocfb avatar Sep 22 '25 17:09 danielocfb

That being said, if you have a different idea or want to look at #350, let us know.

danielocfb avatar Sep 23 '25 16:09 danielocfb

fwiw another use case I could have for this - allow adding custom traits like https://docs.rs/fields-iter/latest/fields_iter/ to allow iterating the generated Progs, Links etc without taking a ref of the bpf_object holder.

Jongy avatar Oct 12 '25 10:10 Jongy