Skip to content

Generating cargo doc for both userland and eBPF program #1260

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

Open
ErrorTeaPot opened this issue Apr 29, 2025 · 3 comments · May be fixed by aya-rs/aya-template#146
Open

Generating cargo doc for both userland and eBPF program #1260

ErrorTeaPot opened this issue Apr 29, 2025 · 3 comments · May be fixed by aya-rs/aya-template#146

Comments

@ErrorTeaPot
Copy link

I am trying to generate documentation using cargo doc in my aya-rs program, but it is only generating the userland part.

I am following the aya-rs template for my project with all the defaults regarding build.rs files and Cargo.toml files. When running cargo doc -r --open --no-deps I have at the end all the documentation of the foo and foo-common part, but foo-ebpf only returns the content of foo-ebpf/src/lib.rs.

How could I generate documentation for all the project at once, with everything at the right place ? (I would like to avoid generating 2 different docs).

@tamird
Copy link
Member

tamird commented Apr 29, 2025

I am not sure this is possible, as the userland and ebpf portions build on different targets.

@miniduikboot
Copy link

It's possible, and not actually that difficult. If you run cargo doc --workspace you get a helpful error message:

error: document output filename collision
The bin `asdfghjkl` in package `asdfghjkl-ebpf v0.1.0 (/tmp/asdfghjkl/asdfghjkl-ebpf)` has the same name as the bin `asdfghjkl` in package `asdfghjkl v0.1.0 (/tmp/asdfghjkl/asdfghjkl)`.
Only one may be documented at once since they output to the same path.
Consider documenting only one, renaming one, or marking one with `doc = false` in Cargo.toml.

If you rename the output of your ebpf module, it's possible to generate docs for both platforms. PR to the template incoming :)

Unfortunately you do need to pass --workspace (or --all, but it's deprecated) to cargo doc, and the Cargo Book doesn't list a way around this, adding the ebpf crate to default-members causes more issues: https://doc.rust-lang.org/cargo/commands/cargo-doc.html#package-selection

miniduikboot added a commit to miniduikboot/aya-template that referenced this issue Apr 29, 2025
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: aya-rs/aya#1260
@miniduikboot miniduikboot linked a pull request Apr 29, 2025 that will close this issue
@ErrorTeaPot
Copy link
Author

Ok, thank you, I have seen this solution, but I was not sure if renaming the module would cause problems.
Thank you for your answer, and I hope that the PR on the template will help !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants