libbpf-rs icon indicating copy to clipboard operation
libbpf-rs copied to clipboard

Add option to extract vendored headers to stable path

Open emmaworley opened this issue 2 years ago • 2 comments

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.

emmaworley avatar Aug 30 '23 20:08 emmaworley

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.

danielocfb avatar Sep 06 '23 17:09 danielocfb

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.

emmaworley avatar Sep 06 '23 17:09 emmaworley