From 59d0627d72cd5ac2a7c5b60132775eb7c178967a Mon Sep 17 00:00:00 2001 From: miniduikboot Date: Tue, 29 Apr 2025 23:23:57 +0200 Subject: [PATCH 1/3] Rename output of -ebpf crate This makes it possible to run `cargo doc --workspace` and get both the eBPF and normal crate and their dependencies in the output docs. Fixes: https://github.com/aya-rs/aya/issues/1260 --- {{project-name}}-ebpf/Cargo.toml | 2 +- {{project-name}}/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/{{project-name}}-ebpf/Cargo.toml b/{{project-name}}-ebpf/Cargo.toml index 370ea43..aec62c5 100644 --- a/{{project-name}}-ebpf/Cargo.toml +++ b/{{project-name}}-ebpf/Cargo.toml @@ -13,5 +13,5 @@ aya-log-ebpf = { workspace = true } which = { workspace = true } [[bin]] -name = "{{ project-name }}" +name = "{{ project-name }}_ebpf" path = "src/main.rs" diff --git a/{{project-name}}/src/main.rs b/{{project-name}}/src/main.rs index b558ec8..c40b800 100644 --- a/{{project-name}}/src/main.rs +++ b/{{project-name}}/src/main.rs @@ -94,7 +94,7 @@ async fn main() -> anyhow::Result<()> { // reach for `Bpf::load_file` instead. let mut ebpf = aya::Ebpf::load(aya::include_bytes_aligned!(concat!( env!("OUT_DIR"), - "/{{project-name}}" + "/{{project-name}}_ebpf" )))?; match aya_log::EbpfLogger::init(&mut ebpf) { Err(e) => { From b97fd36ad5ad46ce8d715ef38a2e8796c1888b82 Mon Sep 17 00:00:00 2001 From: miniduikboot Date: Tue, 29 Apr 2025 23:41:21 +0200 Subject: [PATCH 2/3] Check in CI if unified docs can be generated --- test.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test.sh b/test.sh index 76076ef..96a2b9f 100755 --- a/test.sh +++ b/test.sh @@ -116,6 +116,9 @@ case $OS in eof { } } EOF + + # Check if documentation can be generated for both the userspace and eBPF side at the same time + cargo doc --workspace ;; *) echo "Unsupported OS: ${OS}" From 1f3cd0446d22845aa54198357769adcc365763c8 Mon Sep 17 00:00:00 2001 From: miniduikboot Date: Sun, 7 Sep 2025 00:52:51 +0200 Subject: [PATCH 3/3] Add docs for bin source, not lib source code If a crate has both a lib and a bin target, cargo will prefer to generate for the library target[1]. By renaming the library target, we force cargo to document the binary instead. [1]: https://github.com/rust-lang/cargo/blob/3b379fcc541b39321a7758552d37e5e0cc4277b9/src/doc/src/reference/cargo-targets.md#the-doc-field --- {{project-name}}-ebpf/Cargo.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/{{project-name}}-ebpf/Cargo.toml b/{{project-name}}-ebpf/Cargo.toml index aec62c5..a3639a8 100644 --- a/{{project-name}}-ebpf/Cargo.toml +++ b/{{project-name}}-ebpf/Cargo.toml @@ -15,3 +15,10 @@ which = { workspace = true } [[bin]] name = "{{ project-name }}_ebpf" path = "src/main.rs" + +# Tip: if you want to get aya-ebpf documentation in your crate docs, try +# running `cargo doc --all`. This block makes cargo doc skip the dummy library +# (see {{ project-name }}/Cargo.toml for more details) +[lib] +name = "{{ project-name | snake_case }}_ebpf_dummy" +doc = false