Skip to content

bpf2go: add compdb export#1987

Draft
stepbrobd wants to merge 5 commits into
cilium:mainfrom
stepbrobd:compdb
Draft

bpf2go: add compdb export#1987
stepbrobd wants to merge 5 commits into
cilium:mainfrom
stepbrobd:compdb

Conversation

@stepbrobd
Copy link
Copy Markdown

i was trying to use bpf2go in my project where the dev is happening in a nixos machine

the library paths are at non-conventional locations and my editor/lsp wasn't able to find them and not really providing useful suggestions

i temporarily worked around this by adding a similar compdb wrapper around bpf2go (https://github.com/stepbrobd/rfm/blob/3c86b1ec512c83f46f7d7ad7ee88fa1f64efce44/cmd/bpfgen/main.go#L31) to generate compile_commands.json in the project root and i think this could be useful to someone else

Signed-off-by: Yifei Sun <ysun@hey.com>
Signed-off-by: Yifei Sun <ysun@hey.com>
@ti-mo
Copy link
Copy Markdown
Contributor

ti-mo commented Apr 21, 2026

Hi, could you elaborate on the issue with the library paths? Which library are we talking about?

@stepbrobd
Copy link
Copy Markdown
Author

for example a specific version of vmlinux headers, or libbpf and xdp headers that look like this

/nix/store/0y6byys2fd1xzq66vld217g7y69kvqa1-libbpf-1.6.3/include

if i edit the files directly with nvim, clangd can't find the symbols and just generating massive list of errors, and this compdb change basically will create compile_commands.json entries at user specified location on go generate call

for example (i copied from my source and i'm still working on the upstream patch, the final outcome will be more like //go:generate go tool bpf2go -tags linux counter counter.c -compdb ../compile_commands.json):

package probe

//go:generate go tool bpfgen --ident rfm --output-dir . --pkg-config libbpf --compdb ../compile_commands.json ../bpf/rfm_tc.c
$ cat compile_commands.json
[
  {
    "directory": "/home/ysun/Workspace/rfm/bpf",
    "file": "/home/ysun/Workspace/rfm/bpf/rfm_tc.c",
    "arguments": [
      "clang",
      "--target=bpf",
      "-O2",
      "-g",
      "-Wall",
      "-Wno-missing-declarations",
      "-I/home/ysun/Workspace/rfm/bpf/include",
      "-I/home/ysun/Workspace/rfm/bpf/include/vmlinux/x86",
      "-D__TARGET_ARCH_x86",
      "-I/nix/store/0y6byys2fd1xzq66vld217g7y69kvqa1-libbpf-1.6.3/include",
      "-c",
      "/home/ysun/Workspace/rfm/bpf/rfm_tc.c"
    ]
  }
]

Signed-off-by: Yifei Sun <ysun@hey.com>
Signed-off-by: Yifei Sun <ysun@hey.com>
Signed-off-by: Yifei Sun <ysun@hey.com>
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 this pull request may close these issues.

2 participants