Browse Source

rustfmt: group_imports = "StdExternalCrate"

High time we stop debating this; let the robots do the work.
Tamir Duberstein 1 năm trước cách đây
mục cha
commit
d16e607fd4
87 tập tin đã thay đổi với 215 bổ sung212 xóa
  1. 2 1
      aya-bpf-macros/src/btf_tracepoint.rs
  2. 2 1
      aya-bpf-macros/src/cgroup_device.rs
  3. 2 1
      aya-bpf-macros/src/cgroup_skb.rs
  4. 2 1
      aya-bpf-macros/src/cgroup_sock.rs
  5. 2 1
      aya-bpf-macros/src/cgroup_sock_addr.rs
  6. 2 1
      aya-bpf-macros/src/cgroup_sockopt.rs
  7. 2 1
      aya-bpf-macros/src/cgroup_sysctl.rs
  8. 2 1
      aya-bpf-macros/src/fentry.rs
  9. 2 1
      aya-bpf-macros/src/fexit.rs
  10. 2 2
      aya-bpf-macros/src/kprobe.rs
  11. 1 2
      aya-bpf-macros/src/lib.rs
  12. 2 1
      aya-bpf-macros/src/lsm.rs
  13. 3 4
      aya-bpf-macros/src/map.rs
  14. 2 1
      aya-bpf-macros/src/perf_event.rs
  15. 2 2
      aya-bpf-macros/src/raw_tracepoint.rs
  16. 2 1
      aya-bpf-macros/src/sk_lookup.rs
  17. 2 1
      aya-bpf-macros/src/sk_msg.rs
  18. 2 1
      aya-bpf-macros/src/sk_skb.rs
  19. 2 1
      aya-bpf-macros/src/sock_ops.rs
  20. 2 1
      aya-bpf-macros/src/socket_filter.rs
  21. 2 1
      aya-bpf-macros/src/tc.rs
  22. 2 1
      aya-bpf-macros/src/tracepoint.rs
  23. 2 1
      aya-bpf-macros/src/uprobe.rs
  24. 2 1
      aya-bpf-macros/src/xdp.rs
  25. 2 3
      aya-log-ebpf-macros/src/expand.rs
  26. 8 8
      aya-log/src/lib.rs
  27. 6 7
      aya-obj/src/btf/btf.rs
  28. 1 0
      aya-obj/src/btf/info.rs
  29. 4 5
      aya-obj/src/btf/relocation.rs
  30. 3 2
      aya-obj/src/btf/types.rs
  31. 4 8
      aya-obj/src/generated/mod.rs
  32. 2 3
      aya-obj/src/maps.rs
  33. 16 18
      aya-obj/src/obj.rs
  34. 4 6
      aya-obj/src/relocation.rs
  35. 4 5
      aya-obj/src/util.rs
  36. 1 2
      aya-tool/src/bin/aya-tool.rs
  37. 0 1
      aya-tool/src/generate.rs
  38. 5 3
      aya/src/maps/bloom_filter.rs
  39. 4 5
      aya/src/maps/hash_map/hash_map.rs
  40. 2 1
      aya/src/maps/hash_map/mod.rs
  41. 1 2
      aya/src/maps/hash_map/per_cpu_hash_map.rs
  42. 5 3
      aya/src/maps/lpm_trie.rs
  43. 4 5
      aya/src/maps/mod.rs
  44. 1 2
      aya/src/maps/perf/async_perf_event_array.rs
  45. 4 2
      aya/src/maps/perf/perf_buffer.rs
  46. 3 3
      aya/src/maps/sock/mod.rs
  47. 1 2
      aya/src/maps/xdp/cpu_map.rs
  48. 1 2
      aya/src/maps/xdp/dev_map.rs
  49. 1 2
      aya/src/maps/xdp/dev_map_hash.rs
  50. 1 1
      aya/src/maps/xdp/mod.rs
  51. 2 1
      aya/src/pin.rs
  52. 2 2
      aya/src/programs/cgroup_sock.rs
  53. 2 2
      aya/src/programs/cgroup_sock_addr.rs
  54. 2 2
      aya/src/programs/cgroup_sockopt.rs
  55. 1 0
      aya/src/programs/kprobe.rs
  56. 5 5
      aya/src/programs/links.rs
  57. 2 2
      aya/src/programs/mod.rs
  58. 0 1
      aya/src/programs/perf_event.rs
  59. 4 2
      aya/src/programs/probe.rs
  60. 1 2
      aya/src/programs/sk_lookup.rs
  61. 2 1
      aya/src/programs/socket_filter.rs
  62. 2 2
      aya/src/programs/tc.rs
  63. 1 0
      aya/src/programs/trace_point.rs
  64. 3 2
      aya/src/programs/uprobe.rs
  65. 8 7
      aya/src/programs/xdp.rs
  66. 3 2
      aya/src/sys/bpf.rs
  67. 2 2
      aya/src/sys/mod.rs
  68. 1 1
      aya/src/sys/netlink.rs
  69. 1 2
      aya/src/sys/perf_event.rs
  70. 4 3
      aya/src/util.rs
  71. 4 7
      bpf/aya-bpf-bindings/src/lib.rs
  72. 1 4
      bpf/aya-bpf/src/args.rs
  73. 3 4
      bpf/aya-bpf/src/lib.rs
  74. 1 2
      bpf/aya-bpf/src/maps/xdp/cpu_map.rs
  75. 1 2
      bpf/aya-bpf/src/maps/xdp/dev_map.rs
  76. 1 2
      bpf/aya-bpf/src/maps/xdp/dev_map_hash.rs
  77. 1 2
      bpf/aya-bpf/src/maps/xdp/xsk_map.rs
  78. 2 1
      bpf/aya-bpf/src/programs/perf_event.rs
  79. 1 4
      bpf/aya-bpf/src/programs/probe.rs
  80. 2 1
      bpf/aya-bpf/src/programs/tracepoint.rs
  81. 3 2
      rustfmt.toml
  82. 1 2
      test/integration-test/src/tests/btf_relocations.rs
  83. 1 1
      xtask/src/codegen/aya.rs
  84. 3 3
      xtask/src/codegen/aya_bpf_bindings.rs
  85. 2 1
      xtask/src/docs.rs
  86. 2 1
      xtask/src/lib.rs
  87. 2 1
      xtask/src/main.rs

+ 2 - 1
aya-bpf-macros/src/btf_tracepoint.rs

@@ -45,9 +45,10 @@ impl BtfTracePoint {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_btf_tracepoint() {
         let prog = BtfTracePoint::parse(

+ 2 - 1
aya-bpf-macros/src/cgroup_device.rs

@@ -34,9 +34,10 @@ impl CgroupDevice {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_cgroup_device() {
         let prog = CgroupDevice::parse(

+ 2 - 1
aya-bpf-macros/src/cgroup_skb.rs

@@ -48,9 +48,10 @@ impl CgroupSkb {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn cgroup_skb() {
         let prog = CgroupSkb::parse(

+ 2 - 1
aya-bpf-macros/src/cgroup_sock.rs

@@ -46,9 +46,10 @@ impl CgroupSock {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn cgroup_sock_post_bind4() {
         let prog = CgroupSock::parse(

+ 2 - 1
aya-bpf-macros/src/cgroup_sock_addr.rs

@@ -48,9 +48,10 @@ impl CgroupSockAddr {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn cgroup_sock_addr_connect4() {
         let prog = CgroupSockAddr::parse(

+ 2 - 1
aya-bpf-macros/src/cgroup_sockopt.rs

@@ -46,9 +46,10 @@ impl CgroupSockopt {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn cgroup_sockopt_getsockopt() {
         let prog = CgroupSockopt::parse(

+ 2 - 1
aya-bpf-macros/src/cgroup_sysctl.rs

@@ -34,9 +34,10 @@ impl CgroupSysctl {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_cgroup_sysctl() {
         let prog = CgroupSysctl::parse(

+ 2 - 1
aya-bpf-macros/src/fentry.rs

@@ -51,9 +51,10 @@ impl FEntry {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_fentry() {
         let prog = FEntry::parse(

+ 2 - 1
aya-bpf-macros/src/fexit.rs

@@ -51,9 +51,10 @@ impl FExit {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_fexit() {
         let prog = FExit::parse(

+ 2 - 2
aya-bpf-macros/src/kprobe.rs

@@ -1,7 +1,6 @@
 use std::borrow::Cow;
 
 use proc_macro2::TokenStream;
-
 use quote::quote;
 use syn::{ItemFn, Result};
 
@@ -79,9 +78,10 @@ impl KProbe {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_kprobe() {
         let kprobe = KProbe::parse(

+ 1 - 2
aya-bpf-macros/src/lib.rs

@@ -44,10 +44,9 @@ use sk_msg::SkMsg;
 use sk_skb::{SkSkb, SkSkbKind};
 use sock_ops::SockOps;
 use socket_filter::SocketFilter;
-use uprobe::{UProbe, UProbeKind};
-
 use tc::SchedClassifier;
 use tracepoint::TracePoint;
+use uprobe::{UProbe, UProbeKind};
 use xdp::Xdp;
 #[proc_macro_error]
 #[proc_macro_attribute]

+ 2 - 1
aya-bpf-macros/src/lsm.rs

@@ -53,9 +53,10 @@ impl Lsm {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_lsm_sleepable() {
         let prog = Lsm::parse(

+ 3 - 4
aya-bpf-macros/src/map.rs

@@ -2,11 +2,9 @@ use std::borrow::Cow;
 
 use proc_macro2::TokenStream;
 use quote::quote;
-use syn::Result;
+use syn::{ItemStatic, Result};
 
 use crate::args::name_arg;
-
-use syn::ItemStatic;
 pub(crate) struct Map {
     item: ItemStatic,
     name: String,
@@ -34,9 +32,10 @@ impl Map {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_map_with_name() {
         let map = Map::parse(

+ 2 - 1
aya-bpf-macros/src/perf_event.rs

@@ -35,9 +35,10 @@ impl PerfEvent {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_perf_event() {
         let prog = PerfEvent::parse(

+ 2 - 2
aya-bpf-macros/src/raw_tracepoint.rs

@@ -1,7 +1,6 @@
 use std::borrow::Cow;
 
 use proc_macro2::TokenStream;
-
 use quote::quote;
 use syn::{ItemFn, Result};
 
@@ -45,9 +44,10 @@ impl RawTracePoint {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_raw_tracepoint() {
         let prog = RawTracePoint::parse(

+ 2 - 1
aya-bpf-macros/src/sk_lookup.rs

@@ -34,9 +34,10 @@ impl SkLookup {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_sk_lookup() {
         let prog = SkLookup::parse(

+ 2 - 1
aya-bpf-macros/src/sk_msg.rs

@@ -34,9 +34,10 @@ impl SkMsg {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_sk_msg() {
         let prog = SkMsg::parse(

+ 2 - 1
aya-bpf-macros/src/sk_skb.rs

@@ -56,9 +56,10 @@ impl SkSkb {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_stream_parser() {
         let prog = SkSkb::parse(

+ 2 - 1
aya-bpf-macros/src/sock_ops.rs

@@ -34,9 +34,10 @@ impl SockOps {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_sock_ops() {
         let prog = SockOps::parse(

+ 2 - 1
aya-bpf-macros/src/socket_filter.rs

@@ -34,9 +34,10 @@ impl SocketFilter {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_socket_filter() {
         let prog = SocketFilter::parse(

+ 2 - 1
aya-bpf-macros/src/tc.rs

@@ -34,9 +34,10 @@ impl SchedClassifier {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_sched_classifier() {
         let prog = SchedClassifier::parse(

+ 2 - 1
aya-bpf-macros/src/tracepoint.rs

@@ -52,9 +52,10 @@ impl TracePoint {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_tracepoint() {
         let prog = TracePoint::parse(

+ 2 - 1
aya-bpf-macros/src/uprobe.rs

@@ -104,9 +104,10 @@ impl UProbe {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn uprobe() {
         let uprobe = UProbe::parse(

+ 2 - 1
aya-bpf-macros/src/xdp.rs

@@ -64,9 +64,10 @@ impl Xdp {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use syn::parse_quote;
 
+    use super::*;
+
     #[test]
     fn test_xdp() {
         let prog = Xdp::parse(

+ 2 - 3
aya-log-ebpf-macros/src/expand.rs

@@ -1,3 +1,5 @@
+use aya_log_common::DisplayHint;
+use aya_log_parser::{parse, Fragment};
 use proc_macro2::TokenStream;
 use quote::quote;
 use syn::{
@@ -6,9 +8,6 @@ use syn::{
     Error, Expr, LitStr, Result, Token,
 };
 
-use aya_log_common::DisplayHint;
-use aya_log_parser::{parse, Fragment};
-
 pub(crate) struct LogArgs {
     pub(crate) ctx: Expr,
     pub(crate) target: Option<Expr>,

+ 8 - 8
aya-log/src/lib.rs

@@ -59,13 +59,6 @@ use std::{
 
 const MAP_NAME: &str = "AYA_LOGS";
 
-use aya_log_common::{
-    Argument, DisplayHint, Level, LogValueLength, RecordField, LOG_BUF_CAPACITY, LOG_FIELDS,
-};
-use bytes::BytesMut;
-use log::{error, Log, Record};
-use thiserror::Error;
-
 use aya::{
     maps::{
         perf::{AsyncPerfEventArray, Events, PerfBufferError},
@@ -74,6 +67,12 @@ use aya::{
     util::online_cpus,
     Bpf, Pod,
 };
+use aya_log_common::{
+    Argument, DisplayHint, Level, LogValueLength, RecordField, LOG_BUF_CAPACITY, LOG_FIELDS,
+};
+use bytes::BytesMut;
+use log::{error, Log, Record};
+use thiserror::Error;
 
 #[derive(Copy, Clone)]
 #[repr(transparent)]
@@ -563,10 +562,11 @@ fn try_read<T: Pod>(mut buf: &[u8]) -> Result<(T, &[u8], &[u8]), ()> {
 
 #[cfg(test)]
 mod test {
-    use super::*;
     use aya_log_common::{write_record_header, WriteToBuf};
     use log::{logger, Level};
 
+    use super::*;
+
     fn new_log(args: usize) -> Option<(usize, Vec<u8>)> {
         let mut buf = vec![0; 8192];
         let len = write_record_header(

+ 6 - 7
aya-obj/src/btf/btf.rs

@@ -1,5 +1,3 @@
-use core::{ffi::CStr, mem, ptr};
-
 use alloc::{
     borrow::{Cow, ToOwned as _},
     format,
@@ -7,11 +5,14 @@ use alloc::{
     vec,
     vec::Vec,
 };
-use bytes::BufMut;
+use core::{ffi::CStr, mem, ptr};
 
+use bytes::BufMut;
 use log::debug;
 use object::{Endianness, SectionIndex};
 
+#[cfg(not(feature = "std"))]
+use crate::std;
 use crate::{
     btf::{
         info::{FuncSecInfo, LineSecInfo},
@@ -24,9 +25,6 @@ use crate::{
     Object,
 };
 
-#[cfg(not(feature = "std"))]
-use crate::std;
-
 pub(crate) const MAX_RESOLVE_DEPTH: u8 = 32;
 pub(crate) const MAX_SPEC_LEN: usize = 64;
 
@@ -1102,12 +1100,13 @@ pub(crate) struct SecInfo<'a> {
 
 #[cfg(test)]
 mod tests {
+    use assert_matches::assert_matches;
+
     use super::*;
     use crate::btf::{
         BtfEnum64, BtfParam, DataSec, DataSecEntry, DeclTag, Enum64, Float, Func, FuncProto, Ptr,
         TypeTag, Var,
     };
-    use assert_matches::assert_matches;
 
     #[test]
     fn test_parse_header() {

+ 1 - 0
aya-obj/src/btf/info.rs

@@ -1,4 +1,5 @@
 use alloc::{string::String, vec, vec::Vec};
+
 use bytes::BufMut;
 use object::Endianness;
 

+ 4 - 5
aya-obj/src/btf/relocation.rs

@@ -1,5 +1,3 @@
-use core::{mem, ops::Bound::Included, ptr};
-
 use alloc::{
     borrow::{Cow, ToOwned as _},
     collections::BTreeMap,
@@ -8,8 +6,12 @@ use alloc::{
     vec,
     vec::Vec,
 };
+use core::{mem, ops::Bound::Included, ptr};
+
 use object::SectionIndex;
 
+#[cfg(not(feature = "std"))]
+use crate::std;
 use crate::{
     btf::{
         fields_are_compatible, types_are_compatible, Array, Btf, BtfError, BtfMember, BtfType,
@@ -23,9 +25,6 @@ use crate::{
     Function, Object,
 };
 
-#[cfg(not(feature = "std"))]
-use crate::std;
-
 /// The error type returned by [`Object::relocate_btf`].
 #[derive(thiserror::Error, Debug)]
 #[error("error relocating `{section}`")]

+ 3 - 2
aya-obj/src/btf/types.rs

@@ -1,8 +1,8 @@
 #![allow(missing_docs)]
 
+use alloc::{string::ToString, vec, vec::Vec};
 use core::{fmt::Display, mem, ptr};
 
-use alloc::{string::ToString, vec, vec::Vec};
 use object::Endianness;
 
 use crate::btf::{Btf, BtfError, MAX_RESOLVE_DEPTH};
@@ -1570,9 +1570,10 @@ fn bytes_of<T>(val: &T) -> &[u8] {
 }
 #[cfg(test)]
 mod tests {
-    use super::*;
     use assert_matches::assert_matches;
 
+    use super::*;
+
     #[test]
     fn test_read_btf_type_int() {
         let endianness = Endianness::default();

+ 4 - 8
aya-obj/src/generated/mod.rs

@@ -21,15 +21,11 @@ mod linux_bindings_x86_64;
 // don't re-export __u8 __u16 etc which are already exported by the
 // linux_bindings_* module
 pub use btf_internal_bindings::{bpf_core_relo, bpf_core_relo_kind, btf_ext_header};
-
-#[cfg(target_arch = "x86_64")]
-pub use linux_bindings_x86_64::*;
-
-#[cfg(target_arch = "arm")]
-pub use linux_bindings_armv7::*;
-
 #[cfg(target_arch = "aarch64")]
 pub use linux_bindings_aarch64::*;
-
+#[cfg(target_arch = "arm")]
+pub use linux_bindings_armv7::*;
 #[cfg(target_arch = "riscv64")]
 pub use linux_bindings_riscv64::*;
+#[cfg(target_arch = "x86_64")]
+pub use linux_bindings_x86_64::*;

+ 2 - 3
aya-obj/src/maps.rs

@@ -1,12 +1,11 @@
 //! Map struct and type bindings.
 
-use core::mem;
-
-use crate::BpfSectionKind;
 use alloc::vec::Vec;
+use core::mem;
 
 #[cfg(not(feature = "std"))]
 use crate::std;
+use crate::BpfSectionKind;
 
 /// Invalid map type encontered
 pub struct InvalidMapTypeError {

+ 16 - 18
aya-obj/src/obj.rs

@@ -7,7 +7,8 @@ use alloc::{
     string::{String, ToString},
     vec::Vec,
 };
-use core::{ffi::CStr, mem, ptr, str::FromStr};
+use core::{ffi::CStr, mem, ptr, slice::from_raw_parts_mut, str::FromStr};
+
 use log::debug;
 use object::{
     read::{Object as ElfObject, ObjectSection, Section as ObjSection},
@@ -15,27 +16,23 @@ use object::{
     SymbolKind,
 };
 
-use crate::{
-    btf::BtfFeatures,
-    generated::{BPF_CALL, BPF_JMP, BPF_K},
-    maps::{BtfMap, LegacyMap, Map, MINIMUM_MAP_SIZE},
-    programs::XdpAttachType,
-    relocation::*,
-    util::HashMap,
-};
-
 #[cfg(not(feature = "std"))]
 use crate::std;
-
 use crate::{
-    btf::{Btf, BtfError, BtfExt, BtfType},
-    generated::{bpf_insn, bpf_map_info, bpf_map_type::BPF_MAP_TYPE_ARRAY, BPF_F_RDONLY_PROG},
-    maps::{bpf_map_def, BtfMapDef, PinningType},
-    programs::{CgroupSockAddrAttachType, CgroupSockAttachType, CgroupSockoptAttachType},
+    btf::{
+        Array, Btf, BtfError, BtfExt, BtfFeatures, BtfType, DataSecEntry, FuncSecInfo, LineSecInfo,
+    },
+    generated::{
+        bpf_insn, bpf_map_info, bpf_map_type::BPF_MAP_TYPE_ARRAY, BPF_CALL, BPF_F_RDONLY_PROG,
+        BPF_JMP, BPF_K,
+    },
+    maps::{bpf_map_def, BtfMap, BtfMapDef, LegacyMap, Map, PinningType, MINIMUM_MAP_SIZE},
+    programs::{
+        CgroupSockAddrAttachType, CgroupSockAttachType, CgroupSockoptAttachType, XdpAttachType,
+    },
+    relocation::*,
+    util::HashMap,
 };
-use core::slice::from_raw_parts_mut;
-
-use crate::btf::{Array, DataSecEntry, FuncSecInfo, LineSecInfo};
 
 const KERNEL_VERSION_ANY: u32 = 0xFFFF_FFFE;
 
@@ -1395,6 +1392,7 @@ fn get_func_and_line_info(
 #[cfg(test)]
 mod tests {
     use alloc::vec;
+
     use assert_matches::assert_matches;
     use object::Endianness;
 

+ 4 - 6
aya-obj/src/relocation.rs

@@ -1,11 +1,13 @@
 //! Program relocation handling.
 
+use alloc::{borrow::ToOwned, collections::BTreeMap, string::String};
 use core::mem;
 
-use alloc::{borrow::ToOwned, collections::BTreeMap, string::String};
 use log::debug;
 use object::{SectionIndex, SymbolKind};
 
+#[cfg(not(feature = "std"))]
+use crate::std;
 use crate::{
     generated::{
         bpf_insn, BPF_CALL, BPF_JMP, BPF_K, BPF_PSEUDO_CALL, BPF_PSEUDO_FUNC, BPF_PSEUDO_MAP_FD,
@@ -17,9 +19,6 @@ use crate::{
     BpfSectionKind,
 };
 
-#[cfg(not(feature = "std"))]
-use crate::std;
-
 pub(crate) const INS_SIZE: usize = mem::size_of::<bpf_insn>();
 
 /// The error type returned by [`Object::relocate_maps`] and [`Object::relocate_calls`]
@@ -498,13 +497,12 @@ fn insn_is_call(ins: &bpf_insn) -> bool {
 mod test {
     use alloc::{string::ToString, vec, vec::Vec};
 
+    use super::*;
     use crate::{
         maps::{BtfMap, LegacyMap, Map},
         BpfSectionKind,
     };
 
-    use super::*;
-
     fn fake_sym(index: usize, section_index: usize, address: u64, name: &str, size: u64) -> Symbol {
         Symbol {
             index,

+ 4 - 5
aya-obj/src/util.rs

@@ -1,14 +1,13 @@
 use core::{mem, slice};
-
-#[cfg(not(feature = "std"))]
-pub(crate) use hashbrown::HashMap;
 #[cfg(feature = "std")]
 pub(crate) use std::collections::HashMap;
+#[cfg(feature = "std")]
+pub(crate) use std::collections::HashSet;
 
+#[cfg(not(feature = "std"))]
+pub(crate) use hashbrown::HashMap;
 #[cfg(not(feature = "std"))]
 pub(crate) use hashbrown::HashSet;
-#[cfg(feature = "std")]
-pub(crate) use std::collections::HashSet;
 
 /// bytes_of converts a <T> to a byte slice
 pub(crate) unsafe fn bytes_of<T>(val: &T) -> &[u8] {

+ 1 - 2
aya-tool/src/bin/aya-tool.rs

@@ -1,7 +1,6 @@
-use aya_tool::generate::{generate, InputFile};
-
 use std::{path::PathBuf, process::exit};
 
+use aya_tool::generate::{generate, InputFile};
 use clap::Parser;
 
 #[derive(Parser)]

+ 0 - 1
aya-tool/src/generate.rs

@@ -7,7 +7,6 @@ use std::{
 };
 
 use tempfile::tempdir;
-
 use thiserror::Error;
 
 use crate::bindgen;

+ 5 - 3
aya/src/maps/bloom_filter.rs

@@ -79,6 +79,11 @@ impl<T: BorrowMut<MapData>, V: Pod> BloomFilter<T, V> {
 
 #[cfg(test)]
 mod tests {
+    use std::{ffi::c_long, io};
+
+    use assert_matches::assert_matches;
+    use libc::{EFAULT, ENOENT};
+
     use super::*;
     use crate::{
         bpf_map_def,
@@ -90,9 +95,6 @@ mod tests {
         obj::{self, maps::LegacyMap, BpfSectionKind},
         sys::{override_syscall, SysResult, Syscall},
     };
-    use assert_matches::assert_matches;
-    use libc::{EFAULT, ENOENT};
-    use std::{ffi::c_long, io};
 
     fn new_obj_map() -> obj::Map {
         obj::Map::Legacy(LegacyMap {

+ 4 - 5
aya/src/maps/hash_map/hash_map.rs

@@ -108,6 +108,10 @@ mod tests {
     use assert_matches::assert_matches;
     use libc::{EFAULT, ENOENT};
 
+    use super::{
+        super::test_utils::{self, new_map},
+        *,
+    };
     use crate::{
         generated::{
             bpf_attr, bpf_cmd,
@@ -118,11 +122,6 @@ mod tests {
         sys::{override_syscall, SysResult, Syscall},
     };
 
-    use super::{
-        super::test_utils::{self, new_map},
-        *,
-    };
-
     fn new_obj_map() -> obj::Map {
         test_utils::new_obj_map(BPF_MAP_TYPE_HASH)
     }

+ 2 - 1
aya/src/maps/hash_map/mod.rs

@@ -1,10 +1,11 @@
 //! Hash map types.
+use std::os::fd::AsFd as _;
+
 use crate::{
     maps::MapError,
     sys::{bpf_map_delete_elem, bpf_map_update_elem, SyscallError},
     Pod,
 };
-use std::os::fd::AsFd as _;
 
 #[allow(clippy::module_inception)]
 mod hash_map;

+ 1 - 2
aya/src/maps/hash_map/per_cpu_hash_map.rs

@@ -150,13 +150,12 @@ impl<T: Borrow<MapData>, K: Pod, V: Pod> IterableMap<K, PerCpuValues<V>>
 
 #[cfg(test)]
 mod tests {
+    use super::{super::test_utils, *};
     use crate::{
         generated::bpf_map_type::{BPF_MAP_TYPE_LRU_PERCPU_HASH, BPF_MAP_TYPE_PERCPU_HASH},
         maps::Map,
     };
 
-    use super::{super::test_utils, *};
-
     #[test]
     fn test_try_from_ok() {
         let map = Map::PerCpuHashMap(test_utils::new_map(test_utils::new_obj_map(

+ 5 - 3
aya/src/maps/lpm_trie.rs

@@ -196,6 +196,11 @@ impl<T: Borrow<MapData>, K: Pod, V: Pod> IterableMap<Key<K>, V> for LpmTrie<T, K
 
 #[cfg(test)]
 mod tests {
+    use std::{ffi::c_long, io, mem, net::Ipv4Addr};
+
+    use assert_matches::assert_matches;
+    use libc::{EFAULT, ENOENT};
+
     use super::*;
     use crate::{
         bpf_map_def,
@@ -207,9 +212,6 @@ mod tests {
         obj::{self, maps::LegacyMap, BpfSectionKind},
         sys::{override_syscall, SysResult, Syscall},
     };
-    use assert_matches::assert_matches;
-    use libc::{EFAULT, ENOENT};
-    use std::{ffi::c_long, io, mem, net::Ipv4Addr};
 
     fn new_obj_map() -> obj::Map {
         obj::Map::Legacy(LegacyMap {

+ 4 - 5
aya/src/maps/mod.rs

@@ -58,7 +58,6 @@ use std::{
     ptr,
 };
 
-use crate::util::KernelVersion;
 use libc::{getrlimit, rlim_t, rlimit, RLIMIT_MEMLOCK, RLIM_INFINITY};
 use log::warn;
 use thiserror::Error;
@@ -70,7 +69,7 @@ use crate::{
         bpf_create_map, bpf_get_object, bpf_map_freeze, bpf_map_get_info_by_fd,
         bpf_map_get_next_key, bpf_map_update_elem_ptr, bpf_pin_object, SyscallError,
     },
-    util::nr_cpus,
+    util::{nr_cpus, KernelVersion},
     PinningType, Pod,
 };
 
@@ -807,10 +806,12 @@ impl<T: Pod> Deref for PerCpuValues<T> {
 
 #[cfg(test)]
 mod tests {
+    use std::os::fd::AsRawFd as _;
+
     use assert_matches::assert_matches;
     use libc::EFAULT;
-    use std::os::fd::AsRawFd as _;
 
+    use super::*;
     use crate::{
         bpf_map_def,
         generated::{bpf_cmd, bpf_map_type::BPF_MAP_TYPE_HASH},
@@ -819,8 +820,6 @@ mod tests {
         sys::{override_syscall, Syscall},
     };
 
-    use super::*;
-
     fn new_obj_map() -> obj::Map {
         obj::Map::Legacy(LegacyMap {
             def: bpf_map_def {

+ 1 - 2
aya/src/maps/perf/async_perf_event_array.rs

@@ -1,4 +1,3 @@
-use bytes::BytesMut;
 use std::borrow::{Borrow, BorrowMut};
 
 // See https://doc.rust-lang.org/cargo/reference/features.html#mutually-exclusive-features.
@@ -7,7 +6,7 @@ use std::borrow::{Borrow, BorrowMut};
 // "async-async-std". Presently we arbitrarily choose tokio over async-std when both are requested.
 #[cfg(all(not(feature = "async_tokio"), feature = "async_std"))]
 use async_io::Async;
-
+use bytes::BytesMut;
 #[cfg(feature = "async_tokio")]
 use tokio::io::unix::AsyncFd;
 

+ 4 - 2
aya/src/maps/perf/perf_buffer.rs

@@ -318,13 +318,15 @@ struct LostSamples {
 
 #[cfg(test)]
 mod tests {
+    use std::{fmt::Debug, mem};
+
+    use assert_matches::assert_matches;
+
     use super::*;
     use crate::{
         generated::perf_event_mmap_page,
         sys::{override_syscall, Syscall, TEST_MMAP_RET},
     };
-    use assert_matches::assert_matches;
-    use std::{fmt::Debug, mem};
 
     const PAGE_SIZE: usize = 4096;
     union MMappedBuf {

+ 3 - 3
aya/src/maps/sock/mod.rs

@@ -2,14 +2,14 @@
 mod sock_hash;
 mod sock_map;
 
-pub use sock_hash::SockHash;
-pub use sock_map::SockMap;
-
 use std::{
     io,
     os::fd::{AsFd, BorrowedFd},
 };
 
+pub use sock_hash::SockHash;
+pub use sock_map::SockMap;
+
 /// A socket map file descriptor.
 #[repr(transparent)]
 pub struct SockMapFd(super::MapFd);

+ 1 - 2
aya/src/maps/xdp/cpu_map.rs

@@ -8,6 +8,7 @@ use std::{
 
 use aya_obj::generated::bpf_cpumap_val;
 
+use super::XdpMapError;
 use crate::{
     maps::{check_bounds, check_kv_size, IterableMap, MapData, MapError},
     programs::ProgramFd,
@@ -15,8 +16,6 @@ use crate::{
     Pod, FEATURES,
 };
 
-use super::XdpMapError;
-
 /// An array of available CPUs.
 ///
 /// XDP programs can use this map to redirect packets to a target

+ 1 - 2
aya/src/maps/xdp/dev_map.rs

@@ -8,6 +8,7 @@ use std::{
 
 use aya_obj::generated::bpf_devmap_val;
 
+use super::XdpMapError;
 use crate::{
     maps::{check_bounds, check_kv_size, IterableMap, MapData, MapError},
     programs::ProgramFd,
@@ -15,8 +16,6 @@ use crate::{
     Pod, FEATURES,
 };
 
-use super::XdpMapError;
-
 /// An array of network devices.
 ///
 /// XDP programs can use this map to redirect to other network

+ 1 - 2
aya/src/maps/xdp/dev_map_hash.rs

@@ -8,6 +8,7 @@ use std::{
 
 use aya_obj::generated::bpf_devmap_val;
 
+use super::{dev_map::DevMapValue, XdpMapError};
 use crate::{
     maps::{check_kv_size, hash_map, IterableMap, MapData, MapError, MapIter, MapKeys},
     programs::ProgramFd,
@@ -15,8 +16,6 @@ use crate::{
     FEATURES,
 };
 
-use super::{dev_map::DevMapValue, XdpMapError};
-
 /// An hashmap of network devices.
 ///
 /// XDP programs can use this map to redirect to other network

+ 1 - 1
aya/src/maps/xdp/mod.rs

@@ -7,10 +7,10 @@ mod xsk_map;
 pub use cpu_map::CpuMap;
 pub use dev_map::DevMap;
 pub use dev_map_hash::DevMapHash;
+use thiserror::Error;
 pub use xsk_map::XskMap;
 
 use super::MapError;
-use thiserror::Error;
 
 #[derive(Error, Debug)]
 /// Errors occuring from working with XDP maps.

+ 2 - 1
aya/src/pin.rs

@@ -1,8 +1,9 @@
 //! Pinning BPF objects to the BPF filesystem.
 
-use crate::sys::SyscallError;
 use thiserror::Error;
 
+use crate::sys::SyscallError;
+
 /// An error ocurred working with a pinned BPF object.
 #[derive(Error, Debug)]
 pub enum PinError {

+ 2 - 2
aya/src/programs/cgroup_sock.rs

@@ -1,9 +1,9 @@
 //! Cgroup socket programs.
 
-pub use aya_obj::programs::CgroupSockAttachType;
-
 use std::{hash::Hash, os::fd::AsFd, path::Path};
 
+pub use aya_obj::programs::CgroupSockAttachType;
+
 use crate::{
     generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCK,
     programs::{

+ 2 - 2
aya/src/programs/cgroup_sock_addr.rs

@@ -1,9 +1,9 @@
 //! Cgroup socket address programs.
 
-pub use aya_obj::programs::CgroupSockAddrAttachType;
-
 use std::{hash::Hash, os::fd::AsFd, path::Path};
 
+pub use aya_obj::programs::CgroupSockAddrAttachType;
+
 use crate::{
     generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
     programs::{

+ 2 - 2
aya/src/programs/cgroup_sockopt.rs

@@ -1,9 +1,9 @@
 //! Cgroup socket option programs.
 
-pub use aya_obj::programs::CgroupSockoptAttachType;
-
 use std::{hash::Hash, os::fd::AsFd, path::Path};
 
+pub use aya_obj::programs::CgroupSockoptAttachType;
+
 use crate::{
     generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCKOPT,
     programs::{

+ 1 - 0
aya/src/programs/kprobe.rs

@@ -5,6 +5,7 @@ use std::{
     os::fd::AsFd as _,
     path::{Path, PathBuf},
 };
+
 use thiserror::Error;
 
 use crate::{

+ 5 - 5
aya/src/programs/links.rs

@@ -1,6 +1,4 @@
 //! Program links.
-use thiserror::Error;
-
 use std::{
     collections::{hash_map::Entry, HashMap},
     ffi::CString,
@@ -9,6 +7,8 @@ use std::{
     path::{Path, PathBuf},
 };
 
+use thiserror::Error;
+
 use crate::{
     generated::bpf_attach_type,
     pin::PinError,
@@ -357,13 +357,13 @@ pub enum LinkError {
 
 #[cfg(test)]
 mod tests {
-    use assert_matches::assert_matches;
     use std::{cell::RefCell, fs::File, rc::Rc};
-    use tempfile::tempdir;
 
-    use crate::{programs::ProgramError, sys::override_syscall};
+    use assert_matches::assert_matches;
+    use tempfile::tempdir;
 
     use super::{FdLink, Link, LinkMap};
+    use crate::{programs::ProgramError, sys::override_syscall};
 
     #[derive(Debug, Hash, Eq, PartialEq)]
     struct TestLinkId(u8, u8);

+ 2 - 2
aya/src/programs/mod.rs

@@ -64,7 +64,6 @@ pub mod uprobe;
 mod utils;
 pub mod xdp;
 
-use libc::ENOSPC;
 use std::{
     ffi::CString,
     io,
@@ -74,7 +73,6 @@ use std::{
     sync::Arc,
     time::{Duration, SystemTime},
 };
-use thiserror::Error;
 
 pub use cgroup_device::CgroupDevice;
 pub use cgroup_skb::{CgroupSkb, CgroupSkbAttachType};
@@ -86,6 +84,7 @@ pub use extension::{Extension, ExtensionError};
 pub use fentry::FEntry;
 pub use fexit::FExit;
 pub use kprobe::{KProbe, KProbeError};
+use libc::ENOSPC;
 pub use links::Link;
 use links::*;
 pub use lirc_mode2::LircMode2;
@@ -100,6 +99,7 @@ pub use sk_skb::{SkSkb, SkSkbKind};
 pub use sock_ops::SockOps;
 pub use socket_filter::{SocketFilter, SocketFilterError};
 pub use tc::{SchedClassifier, TcAttachType, TcError};
+use thiserror::Error;
 pub use tp_btf::BtfTracePoint;
 pub use trace_point::{TracePoint, TracePointError};
 pub use uprobe::{UProbe, UProbeError};

+ 0 - 1
aya/src/programs/perf_event.rs

@@ -5,7 +5,6 @@ use std::os::fd::AsFd as _;
 pub use crate::generated::{
     perf_hw_cache_id, perf_hw_cache_op_id, perf_hw_cache_op_result_id, perf_hw_id, perf_sw_ids,
 };
-
 use crate::{
     generated::{
         bpf_link_type,

+ 4 - 2
aya/src/programs/probe.rs

@@ -1,5 +1,3 @@
-use crate::util::KernelVersion;
-use libc::pid_t;
 use std::{
     ffi::{OsStr, OsString},
     fmt::Write as _,
@@ -11,6 +9,8 @@ use std::{
     sync::atomic::{AtomicUsize, Ordering},
 };
 
+use libc::pid_t;
+
 use crate::{
     programs::{
         kprobe::KProbeError, perf_attach, perf_attach::PerfLinkInner, perf_attach_debugfs,
@@ -18,6 +18,7 @@ use crate::{
         Link, ProgramData, ProgramError,
     },
     sys::{perf_event_open_probe, perf_event_open_trace_point, SyscallError},
+    util::KernelVersion,
 };
 
 static PROBE_NAME_INDEX: AtomicUsize = AtomicUsize::new(0);
@@ -213,6 +214,7 @@ fn create_probe_event(
     offset: u64,
 ) -> Result<OsString, (PathBuf, io::Error)> {
     use std::os::unix::ffi::OsStrExt as _;
+
     use ProbeKind::*;
 
     let events_file_name = tracefs.join(format!("{}_events", kind.pmu()));

+ 1 - 2
aya/src/programs/sk_lookup.rs

@@ -1,13 +1,12 @@
 use std::os::fd::AsFd;
 
+use super::links::FdLink;
 use crate::{
     generated::{bpf_attach_type::BPF_SK_LOOKUP, bpf_prog_type::BPF_PROG_TYPE_SK_LOOKUP},
     programs::{define_link_wrapper, load_program, FdLinkId, ProgramData, ProgramError},
     sys::{bpf_link_create, LinkTarget, SyscallError},
 };
 
-use super::links::FdLink;
-
 /// A program used to redirect incoming packets to a local socket.
 ///
 /// [`SkLookup`] programs are attached to network namespaces to provide programmable

+ 2 - 1
aya/src/programs/socket_filter.rs

@@ -1,9 +1,10 @@
 //! Socket filter programs.
-use libc::{setsockopt, SOL_SOCKET};
 use std::{
     io, mem,
     os::fd::{AsFd, AsRawFd, RawFd},
 };
+
+use libc::{setsockopt, SOL_SOCKET};
 use thiserror::Error;
 
 use crate::{

+ 2 - 2
aya/src/programs/tc.rs

@@ -1,6 +1,4 @@
 //! Network traffic control programs.
-use thiserror::Error;
-
 use std::{
     ffi::{CStr, CString},
     io,
@@ -8,6 +6,8 @@ use std::{
     path::Path,
 };
 
+use thiserror::Error;
+
 use crate::{
     generated::{
         bpf_prog_type::BPF_PROG_TYPE_SCHED_CLS, TC_H_CLSACT, TC_H_MIN_EGRESS, TC_H_MIN_INGRESS,

+ 1 - 0
aya/src/programs/trace_point.rs

@@ -1,5 +1,6 @@
 //! Tracepoint programs.
 use std::{fs, io, os::fd::AsFd as _, path::Path};
+
 use thiserror::Error;
 
 use crate::{

+ 3 - 2
aya/src/programs/uprobe.rs

@@ -1,6 +1,4 @@
 //! User space probes.
-use libc::pid_t;
-use object::{Object, ObjectSection, ObjectSymbol};
 use std::{
     borrow::Cow,
     error::Error,
@@ -12,6 +10,9 @@ use std::{
     path::{Path, PathBuf},
     sync::Arc,
 };
+
+use libc::pid_t;
+use object::{Object, ObjectSection, ObjectSymbol};
 use thiserror::Error;
 
 use crate::{

+ 8 - 7
aya/src/programs/xdp.rs

@@ -1,11 +1,5 @@
 //! eXpress Data Path (XDP) programs.
 
-use crate::{
-    sys::{LinkTarget, SyscallError},
-    util::KernelVersion,
-};
-use bitflags;
-use libc::if_nametoindex;
 use std::{
     convert::TryFrom,
     ffi::CString,
@@ -14,6 +8,9 @@ use std::{
     os::fd::{AsFd as _, AsRawFd as _, BorrowedFd, RawFd},
     path::Path,
 };
+
+use bitflags;
+use libc::if_nametoindex;
 use thiserror::Error;
 
 use crate::{
@@ -25,7 +22,11 @@ use crate::{
     programs::{
         define_link_wrapper, load_program, FdLink, Link, LinkError, ProgramData, ProgramError,
     },
-    sys::{bpf_link_create, bpf_link_get_info_by_fd, bpf_link_update, netlink_set_xdp_fd},
+    sys::{
+        bpf_link_create, bpf_link_get_info_by_fd, bpf_link_update, netlink_set_xdp_fd, LinkTarget,
+        SyscallError,
+    },
+    util::KernelVersion,
     VerifierLogLevel,
 };
 

+ 3 - 2
aya/src/sys/bpf.rs

@@ -7,7 +7,6 @@ use std::{
     slice,
 };
 
-use crate::util::KernelVersion;
 use assert_matches::assert_matches;
 use libc::{c_char, c_long, ENOENT, ENOSPC};
 use obj::{
@@ -31,6 +30,7 @@ use crate::{
         copy_instructions,
     },
     sys::{syscall, SysResult, Syscall, SyscallError},
+    util::KernelVersion,
     Btf, Pod, VerifierLogLevel, BPF_OBJ_NAME_LEN,
 };
 
@@ -1069,9 +1069,10 @@ pub(crate) fn retry_with_verifier_logs<T>(
 
 #[cfg(test)]
 mod tests {
+    use libc::{EBADF, EINVAL};
+
     use super::*;
     use crate::sys::override_syscall;
-    use libc::{EBADF, EINVAL};
 
     #[test]
     fn test_perf_link_supported() {

+ 2 - 2
aya/src/sys/mod.rs

@@ -5,20 +5,20 @@ mod perf_event;
 #[cfg(test)]
 mod fake;
 
-use libc::{c_int, c_long, pid_t, SYS_bpf, SYS_perf_event_open};
 use std::{
     io, mem,
     os::fd::{AsRawFd as _, BorrowedFd},
 };
-use thiserror::Error;
 
 pub(crate) use bpf::*;
 #[cfg(test)]
 pub(crate) use fake::*;
+use libc::{c_int, c_long, pid_t, SYS_bpf, SYS_perf_event_open};
 #[doc(hidden)]
 pub use netlink::netlink_set_link_up;
 pub(crate) use netlink::*;
 pub(crate) use perf_event::*;
+use thiserror::Error;
 
 use crate::generated::{bpf_attr, bpf_cmd, perf_event_attr};
 

+ 1 - 1
aya/src/sys/netlink.rs

@@ -5,7 +5,6 @@ use std::{
     os::fd::{AsRawFd as _, BorrowedFd, FromRawFd as _, OwnedFd},
     ptr, slice,
 };
-use thiserror::Error;
 
 use libc::{
     getsockname, nlattr, nlmsgerr, nlmsghdr, recv, send, setsockopt, sockaddr_nl, socket,
@@ -14,6 +13,7 @@ use libc::{
     NLM_F_DUMP, NLM_F_ECHO, NLM_F_EXCL, NLM_F_MULTI, NLM_F_REQUEST, RTM_DELTFILTER, RTM_GETTFILTER,
     RTM_NEWQDISC, RTM_NEWTFILTER, RTM_SETLINK, SOCK_RAW, SOL_NETLINK,
 };
+use thiserror::Error;
 
 use crate::{
     generated::{

+ 1 - 2
aya/src/sys/perf_event.rs

@@ -6,6 +6,7 @@ use std::{
 
 use libc::{c_int, pid_t};
 
+use super::{syscall, SysResult, Syscall};
 use crate::generated::{
     perf_event_attr,
     perf_event_sample_format::PERF_SAMPLE_RAW,
@@ -14,8 +15,6 @@ use crate::generated::{
     PERF_FLAG_FD_CLOEXEC,
 };
 
-use super::{syscall, SysResult, Syscall};
-
 #[allow(clippy::too_many_arguments)]
 pub(crate) fn perf_event_open(
     perf_type: u32,

+ 4 - 3
aya/src/util.rs

@@ -11,13 +11,13 @@ use std::{
     str::{FromStr, Utf8Error},
 };
 
+use libc::{if_nametoindex, sysconf, uname, utsname, _SC_PAGESIZE};
+
 use crate::{
     generated::{TC_H_MAJ_MASK, TC_H_MIN_MASK},
     Pod,
 };
 
-use libc::{if_nametoindex, sysconf, uname, utsname, _SC_PAGESIZE};
-
 /// Represents a kernel version, in major.minor.release version.
 // Adapted from https://docs.rs/procfs/latest/procfs/sys/kernel/struct.Version.html.
 #[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd)]
@@ -359,9 +359,10 @@ pub(crate) fn bytes_of_slice<T: Pod>(val: &[T]) -> &[u8] {
 
 #[cfg(test)]
 mod tests {
-    use super::*;
     use assert_matches::assert_matches;
 
+    use super::*;
+
     #[test]
     fn test_parse_kernel_version_string() {
         // WSL.

+ 4 - 7
bpf/aya-bpf-bindings/src/lib.rs

@@ -14,17 +14,14 @@ mod aarch64;
 mod riscv64;
 
 mod gen {
-    #[cfg(bpf_target_arch = "x86_64")]
-    pub use super::x86_64::*;
-
-    #[cfg(bpf_target_arch = "arm")]
-    pub use super::armv7::*;
-
     #[cfg(bpf_target_arch = "aarch64")]
     pub use super::aarch64::*;
-
+    #[cfg(bpf_target_arch = "arm")]
+    pub use super::armv7::*;
     #[cfg(bpf_target_arch = "riscv64")]
     pub use super::riscv64::*;
+    #[cfg(bpf_target_arch = "x86_64")]
+    pub use super::x86_64::*;
 }
 pub use gen::helpers;
 

+ 1 - 4
bpf/aya-bpf/src/args.rs

@@ -1,14 +1,11 @@
-use crate::{cty::c_void, helpers::bpf_probe_read};
-
 // aarch64 uses user_pt_regs instead of pt_regs
 #[cfg(not(any(bpf_target_arch = "aarch64", bpf_target_arch = "riscv64")))]
 use crate::bindings::pt_regs;
-
 #[cfg(bpf_target_arch = "aarch64")]
 use crate::bindings::user_pt_regs as pt_regs;
-
 #[cfg(bpf_target_arch = "riscv64")]
 use crate::bindings::user_regs_struct as pt_regs;
+use crate::{cty::c_void, helpers::bpf_probe_read};
 
 /// A trait that indicates a valid type for an argument which can be coerced from a BTF
 /// context.

+ 3 - 4
bpf/aya-bpf/src/lib.rs

@@ -22,13 +22,12 @@ pub mod helpers;
 pub mod maps;
 pub mod programs;
 
-pub use aya_bpf_cty as cty;
-
 use core::ffi::c_void;
-use cty::{c_int, c_long};
-use helpers::{bpf_get_current_comm, bpf_get_current_pid_tgid, bpf_get_current_uid_gid};
 
+pub use aya_bpf_cty as cty;
 pub use aya_bpf_macros as macros;
+use cty::{c_int, c_long};
+use helpers::{bpf_get_current_comm, bpf_get_current_pid_tgid, bpf_get_current_uid_gid};
 
 pub const TASK_COMM_LEN: usize = 16;
 

+ 1 - 2
bpf/aya-bpf/src/maps/xdp/cpu_map.rs

@@ -2,13 +2,12 @@ use core::{cell::UnsafeCell, mem};
 
 use aya_bpf_bindings::bindings::bpf_cpumap_val;
 
+use super::try_redirect_map;
 use crate::{
     bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_CPUMAP},
     maps::PinningType,
 };
 
-use super::try_redirect_map;
-
 /// An array of available CPUs.
 ///
 /// XDP programs can use this map to redirect packets to a target CPU for processing.

+ 1 - 2
bpf/aya-bpf/src/maps/xdp/dev_map.rs

@@ -3,14 +3,13 @@ use core::{cell::UnsafeCell, mem, num::NonZeroU32, ptr::NonNull};
 use aya_bpf_bindings::bindings::bpf_devmap_val;
 use aya_bpf_cty::c_void;
 
+use super::try_redirect_map;
 use crate::{
     bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_DEVMAP},
     helpers::bpf_map_lookup_elem,
     maps::PinningType,
 };
 
-use super::try_redirect_map;
-
 /// An array of network devices.
 ///
 /// XDP programs can use this map to redirect packets to other network deviecs.

+ 1 - 2
bpf/aya-bpf/src/maps/xdp/dev_map_hash.rs

@@ -3,14 +3,13 @@ use core::{cell::UnsafeCell, mem, num::NonZeroU32, ptr::NonNull};
 use aya_bpf_bindings::bindings::bpf_devmap_val;
 use aya_bpf_cty::c_void;
 
+use super::{dev_map::DevMapValue, try_redirect_map};
 use crate::{
     bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_DEVMAP_HASH},
     helpers::bpf_map_lookup_elem,
     maps::PinningType,
 };
 
-use super::{dev_map::DevMapValue, try_redirect_map};
-
 /// A map of network devices.
 ///
 /// XDP programs can use this map to redirect packets to other network devices. It is similar to

+ 1 - 2
bpf/aya-bpf/src/maps/xdp/xsk_map.rs

@@ -3,14 +3,13 @@ use core::{cell::UnsafeCell, mem, ptr::NonNull};
 use aya_bpf_bindings::bindings::bpf_xdp_sock;
 use aya_bpf_cty::c_void;
 
+use super::try_redirect_map;
 use crate::{
     bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_XSKMAP},
     helpers::bpf_map_lookup_elem,
     maps::PinningType,
 };
 
-use super::try_redirect_map;
-
 /// An array of AF_XDP sockets.
 ///
 /// XDP programs can use this map to redirect packets to a target AF_XDP socket using the

+ 2 - 1
bpf/aya-bpf/src/programs/perf_event.rs

@@ -1,6 +1,7 @@
-use crate::BpfContext;
 use core::ffi::c_void;
 
+use crate::BpfContext;
+
 pub struct PerfEventContext {
     ctx: *mut c_void,
 }

+ 1 - 4
bpf/aya-bpf/src/programs/probe.rs

@@ -1,15 +1,12 @@
 use core::ffi::c_void;
 
-use crate::{args::FromPtRegs, BpfContext};
-
 #[cfg(not(any(bpf_target_arch = "aarch64", bpf_target_arch = "riscv64")))]
 use crate::bindings::pt_regs;
-
 #[cfg(bpf_target_arch = "aarch64")]
 use crate::bindings::user_pt_regs as pt_regs;
-
 #[cfg(bpf_target_arch = "riscv64")]
 use crate::bindings::user_regs_struct as pt_regs;
+use crate::{args::FromPtRegs, BpfContext};
 
 pub struct ProbeContext {
     pub regs: *mut pt_regs,

+ 2 - 1
bpf/aya-bpf/src/programs/tracepoint.rs

@@ -1,6 +1,7 @@
-use crate::{helpers::bpf_probe_read, BpfContext};
 use core::ffi::c_void;
 
+use crate::{helpers::bpf_probe_read, BpfContext};
+
 pub struct TracePointContext {
     ctx: *mut c_void,
 }

+ 3 - 2
rustfmt.toml

@@ -1,3 +1,4 @@
-unstable_features = true
-reorder_imports = true
+group_imports = "StdExternalCrate"
 imports_granularity = "Crate"
+reorder_imports = true
+unstable_features = true

+ 1 - 2
test/integration-test/src/tests/btf_relocations.rs

@@ -1,6 +1,5 @@
-use test_case::test_case;
-
 use aya::{maps::Array, programs::UProbe, util::KernelVersion, BpfLoader, Btf, Endianness};
+use test_case::test_case;
 
 #[test_case("enum_signed_32", false, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0x7AAAAAAAi32 as u64)]
 #[test_case("enum_signed_32", true, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0x7BBBBBBBi32 as u64)]

+ 1 - 1
xtask/src/codegen/aya.rs

@@ -1,6 +1,6 @@
-use anyhow::anyhow;
 use std::path::{Path, PathBuf};
 
+use anyhow::anyhow;
 use aya_tool::{bindgen, write_to_file};
 
 use crate::codegen::{Architecture, SysrootOptions};

+ 3 - 3
xtask/src/codegen/aya_bpf_bindings.rs

@@ -1,9 +1,9 @@
-use anyhow::anyhow;
-use proc_macro2::TokenStream;
-use quote::ToTokens;
 use std::path::{Path, PathBuf};
 
+use anyhow::anyhow;
 use aya_tool::{bindgen, write_to_file_fmt};
+use proc_macro2::TokenStream;
+use quote::ToTokens;
 use syn::{parse_str, Item};
 
 use crate::codegen::{

+ 2 - 1
xtask/src/docs.rs

@@ -1,7 +1,8 @@
+use std::{ffi::OsString, fs, io::Write as _, process::Command};
+
 use anyhow::{Context as _, Result};
 use cargo_metadata::Metadata;
 use indoc::{indoc, writedoc};
-use std::{ffi::OsString, fs, io::Write as _, process::Command};
 use xtask::exec;
 
 pub fn docs(metadata: Metadata) -> Result<()> {

+ 2 - 1
xtask/src/lib.rs

@@ -1,6 +1,7 @@
-use anyhow::{bail, Context as _, Result};
 use std::process::Command;
 
+use anyhow::{bail, Context as _, Result};
+
 pub const AYA_BUILD_INTEGRATION_BPF: &str = "AYA_BUILD_INTEGRATION_BPF";
 pub const LIBBPF_DIR: &str = "xtask/libbpf";
 

+ 2 - 1
xtask/src/main.rs

@@ -3,10 +3,11 @@ mod docs;
 mod public_api;
 mod run;
 
+use std::process::Command;
+
 use anyhow::{Context as _, Result};
 use cargo_metadata::{Metadata, MetadataCommand};
 use clap::Parser;
-use std::process::Command;
 use xtask::{exec, LIBBPF_DIR};
 
 #[derive(Parser)]