Selaa lähdekoodia

aya-log-ebpf: tidy up `macro_support`

Move top level items into and remove unused items from `macro_support`.
Tamir Duberstein 3 päivää sitten
vanhempi
commit
8fb19264da

+ 5 - 5
aya-log-ebpf-macros/src/expand.rs

@@ -151,11 +151,11 @@ pub(crate) fn log(args: LogArgs, level: Option<TokenStream>) -> Result<TokenStre
     let len = Ident::new("len", Span::mixed_site());
     let record = Ident::new("record", Span::mixed_site());
     Ok(quote! {
-        match ::aya_log_ebpf::AYA_LOG_BUF.get_ptr_mut(0).and_then(|ptr| unsafe { ptr.as_mut() }) {
+        match ::aya_log_ebpf::macro_support::AYA_LOG_BUF.get_ptr_mut(0).and_then(|ptr| unsafe { ptr.as_mut() }) {
             None => {},
-            Some(::aya_log_ebpf::LogBuf { buf: #buf }) => {
+            Some(::aya_log_ebpf::macro_support::LogBuf { buf: #buf }) => {
                 let _: Option<()> = (|| {
-                    let #size = ::aya_log_ebpf::write_record_header(
+                    let #size = ::aya_log_ebpf::macro_support::write_record_header(
                         #buf,
                         #target,
                         #level,
@@ -168,12 +168,12 @@ pub(crate) fn log(args: LogArgs, level: Option<TokenStream>) -> Result<TokenStre
                     #(
                         {
                             let #buf = #buf.get_mut(#size..)?;
-                            let #len = ::aya_log_ebpf::WriteToBuf::write(#values_iter, #buf)?;
+                            let #len = ::aya_log_ebpf::macro_support::WriteToBuf::write(#values_iter, #buf)?;
                             #size += #len.get();
                         }
                     )*
                     let #record = #buf.get(..#size)?;
-                    ::aya_log_ebpf::AYA_LOGS.output(#ctx, #record, 0);
+                    ::aya_log_ebpf::macro_support::AYA_LOGS.output(#ctx, #record, 0);
                     Some(())
                 })();
             }

+ 25 - 29
ebpf/aya-log-ebpf/src/lib.rs

@@ -1,39 +1,35 @@
 #![no_std]
 #![warn(clippy::cast_lossless, clippy::cast_sign_loss)]
 
-#[cfg(target_arch = "bpf")]
-use aya_ebpf::macros::map;
-use aya_ebpf::maps::{PerCpuArray, PerfEventByteArray};
-pub use aya_log_common::{LOG_BUF_CAPACITY, Level, WriteToBuf, write_record_header};
 pub use aya_log_ebpf_macros::{debug, error, info, log, trace, warn};
 
-#[doc(hidden)]
-#[repr(C)]
-pub struct LogBuf {
-    pub buf: [u8; LOG_BUF_CAPACITY],
-}
-
-#[doc(hidden)]
-// This cfg_attr prevents compilation failures on macOS where the generated section name doesn't
-// meet mach-o's requirements. We wouldn't ordinarily build this crate for macOS, but we do so
-// because the integration-test crate depends on this crate transitively. See comment in
-// test/integration-test/Cargo.toml.
-#[cfg_attr(target_arch = "bpf", map)]
-pub static AYA_LOG_BUF: PerCpuArray<LogBuf> = PerCpuArray::with_max_entries(1, 0);
-
-#[doc(hidden)]
-// This cfg_attr prevents compilation failures on macOS where the generated section name doesn't
-// meet mach-o's requirements. We wouldn't ordinarily build this crate for macOS, but we do so
-// because the integration-test crate depends on this crate transitively. See comment in
-// test/integration-test/Cargo.toml.
-#[cfg_attr(target_arch = "bpf", map)]
-pub static AYA_LOGS: PerfEventByteArray = PerfEventByteArray::new(0);
-
 #[doc(hidden)]
 pub mod macro_support {
+    #[cfg(target_arch = "bpf")]
+    use aya_ebpf::macros::map;
+    use aya_ebpf::maps::{PerCpuArray, PerfEventByteArray};
+    use aya_log_common::LOG_BUF_CAPACITY;
     pub use aya_log_common::{
-        DefaultFormatter, DisplayHint, IpFormatter, LOG_BUF_CAPACITY, Level, LowerHexFormatter,
-        LowerMacFormatter, UpperHexFormatter, UpperMacFormatter,
+        DefaultFormatter, DisplayHint, IpFormatter, Level, LowerHexFormatter, LowerMacFormatter,
+        UpperHexFormatter, UpperMacFormatter, WriteToBuf, write_record_header,
     };
-    pub use aya_log_ebpf_macros::log;
+
+    #[repr(C)]
+    pub struct LogBuf {
+        pub buf: [u8; LOG_BUF_CAPACITY],
+    }
+
+    // This cfg_attr prevents compilation failures on macOS where the generated section name doesn't
+    // meet mach-o's requirements. We wouldn't ordinarily build this crate for macOS, but we do so
+    // because the integration-test crate depends on this crate transitively. See comment in
+    // test/integration-test/Cargo.toml.
+    #[cfg_attr(target_arch = "bpf", map)]
+    pub static AYA_LOG_BUF: PerCpuArray<LogBuf> = PerCpuArray::with_max_entries(1, 0);
+
+    // This cfg_attr prevents compilation failures on macOS where the generated section name doesn't
+    // meet mach-o's requirements. We wouldn't ordinarily build this crate for macOS, but we do so
+    // because the integration-test crate depends on this crate transitively. See comment in
+    // test/integration-test/Cargo.toml.
+    #[cfg_attr(target_arch = "bpf", map)]
+    pub static AYA_LOGS: PerfEventByteArray = PerfEventByteArray::new(0);
 }

+ 0 - 3
xtask/public-api/aya-log-ebpf.txt

@@ -1,7 +1,4 @@
 pub mod aya_log_ebpf
-pub use aya_log_ebpf::LOG_BUF_CAPACITY
-pub use aya_log_ebpf::Level
-pub use aya_log_ebpf::WriteToBuf
 pub use aya_log_ebpf::debug
 pub use aya_log_ebpf::error
 pub use aya_log_ebpf::info