libbpf / libbpf-rs

Minimal and opinionated eBPF tooling for the Rust ecosystem
Other
787 stars 138 forks source link

Add option to extract vendored headers to stable path #571

Open connorworley opened 1 year ago

connorworley commented 1 year ago

I'd like to run clang-tidy on my C code. I can add a clang arg to generate compilation command JSON, but it ends up referring to temporary include paths:

{ "directory": "/Users/cworley/Code/program-template", "file": "src/bpf/template.bpf.c", "output": "/tmp/.tmpR5UzRB/template.o", "arguments": ["/usr/lib/llvm-14/bin/clang", "-xc", "src/bpf/template.bpf.c", "-D", "__TARGET_ARCH_x86", "-I", "/tmp/.tmp5F6kvc/bpf/src", "-fno-stack-protector", "-g", "-O2", "--target=bpf", "-c", "-o", "/tmp/.tmpR5UzRB/template.o", "--target=bpf"]},

It would be nice if there was a way to extract these vendored headers to a stable path such that they still exist when I run clang-tidy.

danielocfb commented 1 year ago

To the degree I can tell the headers will be extracted somewhere below the target directory. How you set that is up to you and depends on how you generate the bindings. Please show the complete working example if that doesn't help.

connorworley commented 1 year ago

Refer to https://github.com/libbpf/libbpf-rs/blob/aacaec1b7dfaa4bf9112d2f4168d77dfceee499f/libbpf-cargo/src/build.rs#L292-L293 -- the headers are extracted to a temporary directory.